26

I'm upgrading from JDK 8 to JDK 17 and I'm trying to compile with mvn clean install -X -DskipTests and there's no information about the error.

Btw, I'm updating the dependencies and after that I compile to see if has errors. I need to update some dependencies such as Spring, Hibernate etc. I already updated Lombok.

I added the -X or -e option but I got the same result.

What can I do to get more information about the error? The log shows that it was loading hibernate-jpa-2.1-api before failed... so that means the problem is in this dependency?

[INFO] [loading /Users/daniela/.m2/repository/org/projectlombok/lombok/1.18.2/lombok-1.18.2.jar(/lombok/AllArgsConstructor$AnyAnnotation.class)]
[INFO] [loading /Users/daniela/.m2/repository/org/ocpsoft/rewrite/rewrite-config-prettyfaces/2.0.4.Final/rewrite-config-prettyfaces-2.0.4.Final.jar(/com/ocpsoft/pretty/faces/annotation/URLValidator.class)]
[INFO] [loading /Users/daniela/.m2/repository/javax/servlet/javax.servlet-api/3.1.0/javax.servlet-api-3.1.0.jar(/javax/servlet/annotation/WebInitParam.class)]
[INFO] [loading /Users/daniela/.m2/repository/org/projectlombok/lombok/1.18.2/lombok-1.18.2.jar(/lombok/RequiredArgsConstructor$AnyAnnotation.class)]
[INFO] [loading /Users/daniela/.m2/repository/org/hibernate/javax/persistence/hibernate-jpa-2.1-api/1.0.0.Final/hibernate-jpa-2.1-api-1.0.0.Final.jar(/javax/persistence/PersistenceProperty.class)]
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary for My App 2.61.0-SNAPSHOT:
[INFO] 
[INFO] My App ............................. SUCCESS [  0.005 s]
[INFO] My App - Webapp .................... FAILURE [  9.454 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  9.555 s
[INFO] Finished at: 2021-09-21T10:31:24-03:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project myapp-webapp: Compilation failure -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project myapp-webapp: Compilation failure
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:215)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:957)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:289)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:193)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:77)
    at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:568)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)
Caused by: org.apache.maven.plugin.compiler.CompilationFailureException: Compilation failure
    at org.apache.maven.plugin.compiler.AbstractCompilerMojo.execute (AbstractCompilerMojo.java:1224)
    at org.apache.maven.plugin.compiler.CompilerMojo.execute (CompilerMojo.java:187)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:210)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:957)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:289)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:193)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:77)
    at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:568)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)
[ERROR] 
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
[ERROR] 
[ERROR] After correcting the problems, you can resume the build with the command
[ERROR]   mvn <args> -rf :myapp-webapp

pom.xml (Parent)

<properties>

        <!-- Generic properties -->
        <java.version>17</java.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>

        <!-- Java EE / Java SE dependencies -->
        <jsp.version>2.2</jsp.version>
        <jstl.version>1.2</jstl.version>
        <servlet.version>3.1.0</servlet.version>
        <javax-el.version>3.0.0</javax-el.version>
        <jaxb-impl.version>2.2.7-b63</jaxb-impl.version>

        <!-- Other dependencies such as Spring, Hibernate etc -->

        <maven.compiler.source>17</maven.compiler.source>
        <maven.compiler.target>17</maven.compiler.target>
</properties>

<build>

        <pluginManagement>

            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.8.1</version>
                    <configuration>
                        <annotationProcessorPaths>
                            <path>
                                <groupId>org.projectlombok</groupId>
                                <artifactId>lombok</artifactId>
                                <version>${lombok.version}</version>
                            </path>
                        </annotationProcessorPaths>
                        <compilerArguments>
                            <verbose />
                            <Xlint />
                        </compilerArguments>
                        <fork>true</fork>
                        <verbose>true</verbose>
                        <source>17</source>
                        <target>17</target>
                        <showWarnings>true</showWarnings>
                        <compilerVersion>17</compilerVersion>
                        <debug>true</debug>
                    </configuration>
                </plugin>

                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-war-plugin</artifactId>
                    <version>2.4</version>
                    <configuration>
                        <warName>${project.build.finalName}</warName>
                    </configuration>
                </plugin>

                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-release-plugin</artifactId>
                    <version>2.5</version>
                    <dependencies>
                        <dependency>
                            <groupId>org.apache.maven.scm</groupId>
                            <artifactId>maven-scm-provider-gitexe</artifactId>
                            <version>1.9.2</version>
                        </dependency>
                    </dependencies>
                    <configuration>
                        <arguments>-Dbuild-env=${build-env}</arguments>
                    </configuration>
                </plugin>

                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-javadoc-plugin</artifactId>
                    <version>2.9</version>
                    <configuration>
                        <skip>true</skip>
                    </configuration>
                </plugin>

                <plugin>
                    <artifactId>maven-clean-plugin</artifactId>
                    <version>2.6.1</version>
                </plugin>

                <plugin>
                    <artifactId>maven-resources-plugin</artifactId>
                    <version>2.7</version>
                    <executions>
                        <execution>
                            <id>copy-resources</id>
                            <phase>validate</phase>
                            <goals>
                                <goal>copy-resources</goal>
                            </goals>
                            <configuration>
                                <outputDirectory>${project.build.outputDirectory}/com/my/app/bundle</outputDirectory>
                                <resources>
                                    <resource>
                                        <directory>src/main/resources/my/app/bundle</directory>
                                        <filtering>true</filtering>
                                    </resource>
                                </resources>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>

                <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-site-plugin</artifactId>
                        <version>3.9.1</version>
                </plugin>

                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-project-info-reports-plugin</artifactId>
                    <version>3.1.2</version>
                </plugin>
            </plugins>

        </pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
            </plugin>

        </plugins>

    </build>

pom.xml (Child)

<properties>
        <java.version>17</java.version>

        <maven.compiler.source>17</maven.compiler.source>
        <maven.compiler.target>17</maven.compiler.target>
</properties>

<profiles>
        <profile>
            <id>dev</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>

            <build>
                <finalName>myapp</finalName>
                <plugins>

                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-war-plugin</artifactId>
                    </plugin>

                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-surefire-plugin</artifactId>
                        <configuration>
                            <includes>
                                <include>**/*IT.java</include>
                            </includes>
                        </configuration>
                        <version>2.18.1</version>
                    </plugin>

                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-compiler-plugin</artifactId>
                        <inherited>true</inherited>
                    </plugin>

                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-dependency-plugin</artifactId>
                    </plugin>
                    <plugin>
                        <artifactId>maven-release-plugin</artifactId>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-site-plugin</artifactId>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-project-info-reports-plugin</artifactId>
                    </plugin>
                </plugins>
            </build>
        </profile>
</profile>      

Java and mvn version

daniela@Danielas-Macbook ~> javac -version
javac 17
daniela@Danielas-Macbook ~> mvn --version
Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)
Maven home: /usr/local/Cellar/maven/3.6.3_1/libexec
Java version: 17

I changed the java version in maven to execute with JDK 8 and JDK 11 and there's no error: BUILD SUCCESS. I got the error in JDK 16 and 17.

Daniela Morais
  • 2,125
  • 7
  • 28
  • 49
  • 1
    Do you also get `Compilation failure` when you use a different java version? Or only when using Java 17 – Lino Sep 21 '21 at 16:33
  • 1
    One thing worth trying is a mvn clean. Usually a good habit imo to run a clean as part of a mvn build (e.g., "mvn clean install" or "mvn clean compile") to rule out any lingering issues from a prior build. – Woodchuck Sep 21 '21 at 16:39
  • Usually there is more in the log output in particular on the module level where the error happens ...you have only posted the final part at the end... also there are some strange things in this build. Using surefireplugin for IT's ? It's not intended for integration tests (failsafe plugin is intended for that)... also using very old versions of them...Why do the child has a profile? If you use `maven.compiler.target` property you don't need to configuration maven-compiler-plugin in pluginManagement that's duplication etc. Please make an example project on github so we can reproduce it... – khmarbaise Sep 21 '21 at 16:52
  • @Lino I tried with JDK 8 and there's no error. I'll try with JDK 11. – Daniela Morais Sep 21 '21 at 17:28
  • @khmarbaise It's a legacy project.. I'll fix this and create an example project on Github. Thanks. – Daniela Morais Sep 21 '21 at 17:31
  • I download maven 3.8.6 from https://maven.apache.org/download.cgi, install in separate directory and alias mnv17 created to it. With JDK17 mvn3.8.6 work fine. – Ryabinin Sergey Jul 25 '22 at 10:29
  • In your particular case, `mvn` is too old for Java 17. Update mvn to a new version, it should fix the issue. In the comment above 3.8.6 version is ok. I used 3.9.2 version and it fixed the issue for me. – Alexandr Jun 14 '23 at 10:01

5 Answers5

16

This failure is likely due to an issue between java 17 and older lombok versions. Building with java 17.0.1, lombok 1.18.20 and maven 3.8.1 caused a vague "Compilation failure" for me as well. I upgraded to maven 3.8.3 which also failed but provided this detail on the failure:

java.lang.NullPointerException: Cannot read field "bindingsWhenTrue" because "currentBindings" is null

Searching for this failure message I found this issue on stackoverflow leading me to a bug in lombok. I upgraded to lombok 1.18.22 and that fixed the compilation failure for a successful build.

NaderNader
  • 1,038
  • 1
  • 11
  • 16
7

Maven compiler for java versions above Java 9 can be set up differently. For me it worked when I replaced:

<properties>
        <maven.compiler.source>17</maven.compiler.source>
        <maven.compiler.target>17</maven.compiler.target>
</properties>

With this code:

<properties>
        <maven.compiler.release>17</maven.compiler.release>
</properties>

This should work for all java versions above Java 9

Rejja Kubzek
  • 81
  • 1
  • 6
3

I tried the fixes here but none of them did the trick. I can confirm the problem happens with Java 17 only.

<plugin>
    <artifactId>maven-compiler-plugin</artifactId>
        <version>3.8.1</version>
        <configuration>
            <source>"insert Java Version here"</source>
            <target>"insert Java Version here"</target>
    </configuration>
</plugin>

It does not matter if my build path matches the POM file, or even if you specify the java version like the example code above. My initial POM file didnt even have the tags.

However, I've found a work around. leave the POM file alone,set your buildpath to java 1.8 then compile. It will be sucesscul. Change it back to java 17 and now it wont throw the error.

I don't know how or why this works but it does and all Java 17 features work as far as I can tell.

Cheers!

BMET1

BMET1
  • 31
  • 1
  • can you give plz give an example of what it will actually look like. For ex: `17` I tried such but didn't work – KNU Aug 24 '23 at 15:44
1

To be honest I've tried all of the above and still got the error. I lost some time checking Java and Maven all was good in console, but IntelliJ was caching versions obviously.

Finally I tried restarting all instances of IDE (IntellJ) and it started working.

starball
  • 20,030
  • 7
  • 43
  • 238
amer
  • 1,528
  • 1
  • 14
  • 22
-3

Installed jre Make sure correct file is selected in the installed jre

Alana
  • 27
  • 3