Unable to compile simple Java 10 / Java 11 project with Maven
I have a trivial Maven project:
src
└── main
└── java
└── module-info.java
pom.xml
pom.xml:
<groupId>org.example</groupId>
<artifactId>example</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>example</name>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<release>10</release>
</configuration>
</plugin>
</plugins>
</build>
When I build the project via mvn -X install -DskipTests=true
, it fails:
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.7.0:testCompile (default-testCompile) on project example: Execution default-testCompile of goal org.apache.maven.plugins:maven-compiler-plugin:3.7.0:testCompile failed.
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:213)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:154)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:146)
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:51)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:309)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:194)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:107)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:993)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:345)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:191)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
Caused by: org.apache.maven.plugin.PluginExecutionException: Execution default-testCompile of goal org.apache.maven.plugins:maven-compiler-plugin:3.7.0:testCompile failed.
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:145)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
... 20 more
Caused by: java.lang.IllegalArgumentException
at org.objectweb.asm.ClassReader.<init>(Unknown Source)
at org.objectweb.asm.ClassReader.<init>(Unknown Source)
at org.objectweb.asm.ClassReader.<init>(Unknown Source)
at org.codehaus.plexus.languages.java.jpms.AsmModuleInfoParser.parse(AsmModuleInfoParser.java:80)
at org.codehaus.plexus.languages.java.jpms.AsmModuleInfoParser.getModuleDescriptor(AsmModuleInfoParser.java:54)
at org.codehaus.plexus.languages.java.jpms.LocationManager.resolvePaths(LocationManager.java:83)
at org.apache.maven.plugin.compiler.TestCompilerMojo.preparePaths(TestCompilerMojo.java:281)
at org.apache.maven.plugin.compiler.AbstractCompilerMojo.execute(AbstractCompilerMojo.java:762)
at org.apache.maven.plugin.compiler.TestCompilerMojo.execute(TestCompilerMojo.java:176)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
... 21 more
Is there a way to fix this?
java maven java-10 java-11 module-info
add a comment |
I have a trivial Maven project:
src
└── main
└── java
└── module-info.java
pom.xml
pom.xml:
<groupId>org.example</groupId>
<artifactId>example</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>example</name>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<release>10</release>
</configuration>
</plugin>
</plugins>
</build>
When I build the project via mvn -X install -DskipTests=true
, it fails:
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.7.0:testCompile (default-testCompile) on project example: Execution default-testCompile of goal org.apache.maven.plugins:maven-compiler-plugin:3.7.0:testCompile failed.
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:213)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:154)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:146)
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:51)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:309)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:194)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:107)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:993)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:345)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:191)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
Caused by: org.apache.maven.plugin.PluginExecutionException: Execution default-testCompile of goal org.apache.maven.plugins:maven-compiler-plugin:3.7.0:testCompile failed.
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:145)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
... 20 more
Caused by: java.lang.IllegalArgumentException
at org.objectweb.asm.ClassReader.<init>(Unknown Source)
at org.objectweb.asm.ClassReader.<init>(Unknown Source)
at org.objectweb.asm.ClassReader.<init>(Unknown Source)
at org.codehaus.plexus.languages.java.jpms.AsmModuleInfoParser.parse(AsmModuleInfoParser.java:80)
at org.codehaus.plexus.languages.java.jpms.AsmModuleInfoParser.getModuleDescriptor(AsmModuleInfoParser.java:54)
at org.codehaus.plexus.languages.java.jpms.LocationManager.resolvePaths(LocationManager.java:83)
at org.apache.maven.plugin.compiler.TestCompilerMojo.preparePaths(TestCompilerMojo.java:281)
at org.apache.maven.plugin.compiler.AbstractCompilerMojo.execute(AbstractCompilerMojo.java:762)
at org.apache.maven.plugin.compiler.TestCompilerMojo.execute(TestCompilerMojo.java:176)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
... 21 more
Is there a way to fix this?
java maven java-10 java-11 module-info
@MikhailKholodkov The bug has been resolved and one can now make use of themaven-compiler-plugin:3.8.0
to fix the above error.
– Naman
Jul 30 '18 at 2:29
add a comment |
I have a trivial Maven project:
src
└── main
└── java
└── module-info.java
pom.xml
pom.xml:
<groupId>org.example</groupId>
<artifactId>example</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>example</name>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<release>10</release>
</configuration>
</plugin>
</plugins>
</build>
When I build the project via mvn -X install -DskipTests=true
, it fails:
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.7.0:testCompile (default-testCompile) on project example: Execution default-testCompile of goal org.apache.maven.plugins:maven-compiler-plugin:3.7.0:testCompile failed.
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:213)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:154)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:146)
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:51)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:309)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:194)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:107)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:993)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:345)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:191)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
Caused by: org.apache.maven.plugin.PluginExecutionException: Execution default-testCompile of goal org.apache.maven.plugins:maven-compiler-plugin:3.7.0:testCompile failed.
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:145)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
... 20 more
Caused by: java.lang.IllegalArgumentException
at org.objectweb.asm.ClassReader.<init>(Unknown Source)
at org.objectweb.asm.ClassReader.<init>(Unknown Source)
at org.objectweb.asm.ClassReader.<init>(Unknown Source)
at org.codehaus.plexus.languages.java.jpms.AsmModuleInfoParser.parse(AsmModuleInfoParser.java:80)
at org.codehaus.plexus.languages.java.jpms.AsmModuleInfoParser.getModuleDescriptor(AsmModuleInfoParser.java:54)
at org.codehaus.plexus.languages.java.jpms.LocationManager.resolvePaths(LocationManager.java:83)
at org.apache.maven.plugin.compiler.TestCompilerMojo.preparePaths(TestCompilerMojo.java:281)
at org.apache.maven.plugin.compiler.AbstractCompilerMojo.execute(AbstractCompilerMojo.java:762)
at org.apache.maven.plugin.compiler.TestCompilerMojo.execute(TestCompilerMojo.java:176)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
... 21 more
Is there a way to fix this?
java maven java-10 java-11 module-info
I have a trivial Maven project:
src
└── main
└── java
└── module-info.java
pom.xml
pom.xml:
<groupId>org.example</groupId>
<artifactId>example</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>example</name>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<release>10</release>
</configuration>
</plugin>
</plugins>
</build>
When I build the project via mvn -X install -DskipTests=true
, it fails:
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.7.0:testCompile (default-testCompile) on project example: Execution default-testCompile of goal org.apache.maven.plugins:maven-compiler-plugin:3.7.0:testCompile failed.
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:213)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:154)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:146)
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:51)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:309)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:194)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:107)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:993)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:345)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:191)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
Caused by: org.apache.maven.plugin.PluginExecutionException: Execution default-testCompile of goal org.apache.maven.plugins:maven-compiler-plugin:3.7.0:testCompile failed.
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:145)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
... 20 more
Caused by: java.lang.IllegalArgumentException
at org.objectweb.asm.ClassReader.<init>(Unknown Source)
at org.objectweb.asm.ClassReader.<init>(Unknown Source)
at org.objectweb.asm.ClassReader.<init>(Unknown Source)
at org.codehaus.plexus.languages.java.jpms.AsmModuleInfoParser.parse(AsmModuleInfoParser.java:80)
at org.codehaus.plexus.languages.java.jpms.AsmModuleInfoParser.getModuleDescriptor(AsmModuleInfoParser.java:54)
at org.codehaus.plexus.languages.java.jpms.LocationManager.resolvePaths(LocationManager.java:83)
at org.apache.maven.plugin.compiler.TestCompilerMojo.preparePaths(TestCompilerMojo.java:281)
at org.apache.maven.plugin.compiler.AbstractCompilerMojo.execute(AbstractCompilerMojo.java:762)
at org.apache.maven.plugin.compiler.TestCompilerMojo.execute(TestCompilerMojo.java:176)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
... 21 more
Is there a way to fix this?
java maven java-10 java-11 module-info
java maven java-10 java-11 module-info
edited Dec 13 '18 at 2:00
Naman
44.8k11102204
44.8k11102204
asked Mar 21 '18 at 5:35
ZhekaKozlovZhekaKozlov
15.7k871115
15.7k871115
@MikhailKholodkov The bug has been resolved and one can now make use of themaven-compiler-plugin:3.8.0
to fix the above error.
– Naman
Jul 30 '18 at 2:29
add a comment |
@MikhailKholodkov The bug has been resolved and one can now make use of themaven-compiler-plugin:3.8.0
to fix the above error.
– Naman
Jul 30 '18 at 2:29
@MikhailKholodkov The bug has been resolved and one can now make use of the
maven-compiler-plugin:3.8.0
to fix the above error.– Naman
Jul 30 '18 at 2:29
@MikhailKholodkov The bug has been resolved and one can now make use of the
maven-compiler-plugin:3.8.0
to fix the above error.– Naman
Jul 30 '18 at 2:29
add a comment |
5 Answers
5
active
oldest
votes
UPDATE
The answer is now obsolete. See this answer.
maven-compiler-plugin
depends on the old version of ASM which does not support Java 10 (and Java 11) yet. However, it is possible to explicitly specify the right version of ASM:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<release>10</release>
</configuration>
<dependencies>
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm</artifactId>
<version>6.2</version> <!-- Use newer version of ASM -->
</dependency>
</dependencies>
</plugin>
You can find the latest at https://search.maven.org/search?q=g:org.ow2.asm%20AND%20a:asm&core=gav
add a comment |
Alternatively, as of 30Jul, 2018 to fix the above issue, one can configure the java version used within maven to any up to JDK/11 and make use of the maven-compiler-plugin:3.8.0
to specify a release of either 9,10,11 without any explicit dependencies.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<release>11</release> <!--or <release>10</release>-->
</configuration>
</plugin>
Note:- The default value for source/target has been lifted from 1.5 to 1.6 with this version. -- release notes.
Edit [30.12.2018]
In fact, you can make use of the same version of maven-compiler-plugin
while compiling the code against JDK/12 as well. Have shared more details and a sample configuration in how to Compile a JDK12 preview feature with Maven.
1
This only works out of the box when maven is executed with Java 11. If your platform Java version is e.g. Java 8 (and so maven is executed with Java 8), you need to define a toolchain maven.apache.org/guides/mini/guide-using-toolchains.html
– Franz Deschler
Jan 11 at 17:16
2
Note that the associated property ismaven.compiler.release
:<properties><maven.compiler.release>11</maven.compiler.release></properties>
– Olivier Grégoire
Feb 26 at 12:20
add a comment |
Boosting your maven-compiler-plugin to 3.8.0 seems to be necessary but not sufficient. If you're still having problems, you should also make sure your JAVA_HOME environment variable is set to Java 10 (or 11) if you're running from the command line. (The error message you get won't tell you this.) Or if you're running from an IDE, you need to make sure it is set to run maven with your current JDK.
add a comment |
Specify maven.compiler.source and target versions.
1) Maven version which supports jdk you use. In my case JDK 11 and maven 3.6.0.
2) pom.xml
<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
As an alternative, you can fully specify maven compiler plugin. See previous answers. It is shorter in my example :)
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<release>11</release>
</configuration>
</plugin>
</plugins>
</build>
3) rebuild the project to avoid compile errors in your IDE.
4) If it still does not work. In Intellij Idea I prefer using terminal instead of using terminal from OS. Then in Idea go to file -> settings -> build tools -> maven. I work with maven I downloaded from apache (by default Idea uses bundled maven). Restart Idea then and run mvn clean install
again. Also make sure you have correct Path, MAVEN_HOME, JAVA_HOME environment variables.
I also saw this one-liner, but it does not work.
<maven.compiler.release>11</maven.compiler.release>
add a comment |
It might not exactly be the same error, but I had a similar one.
Check Maven Java Version
Since Maven is also runnig with Java, check first with which version your Maven is running on:
mvn --version | grep Java
It returns:
Java version 1.8.0_151, vendor: Oracle
Corporation, runtime: C:toolsjdkopenjdk1.8
Incompatible version
Here above my maven is running with Java Version 1.8.0_151
.
So even if I specify maven to compile with Java 11
:
<properties>
<java.version>11</java.version>
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
</properties>
It will logically print out this error:
[ERROR] Failed to execute goal
org.apache.maven.plugins:maven-compiler-plugin:3.8.0:compile
(default-compile) on project efa-example-commons-task: Fatal error
compiling: invalid target release: 11 -> [Help 1]
How to set specific java version to Maven
The logical thing to do is to set a higher Java Version to Maven (e.g. Java version 11 instead 1.8).
Maven make use of the environment variable JAVA_HOME
to find the Java Version to run. So change this variable to the JDK you want to compile against (e.g. OpenJDK 11).
Sanity check
Then run again mvn --version
to make sure the configuration has been taken care of:
λ mvn --version | grep Java Java version: 11.0.2, vendor: Oracle
Corporation, runtime: C:toolsjdkopenjdk11
Which is much better and correct to compile code written with the Java 11 specifications.
add a comment |
protected by cassiomolin Aug 8 '18 at 18:13
Thank you for your interest in this question.
Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).
Would you like to answer one of these unanswered questions instead?
5 Answers
5
active
oldest
votes
5 Answers
5
active
oldest
votes
active
oldest
votes
active
oldest
votes
UPDATE
The answer is now obsolete. See this answer.
maven-compiler-plugin
depends on the old version of ASM which does not support Java 10 (and Java 11) yet. However, it is possible to explicitly specify the right version of ASM:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<release>10</release>
</configuration>
<dependencies>
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm</artifactId>
<version>6.2</version> <!-- Use newer version of ASM -->
</dependency>
</dependencies>
</plugin>
You can find the latest at https://search.maven.org/search?q=g:org.ow2.asm%20AND%20a:asm&core=gav
add a comment |
UPDATE
The answer is now obsolete. See this answer.
maven-compiler-plugin
depends on the old version of ASM which does not support Java 10 (and Java 11) yet. However, it is possible to explicitly specify the right version of ASM:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<release>10</release>
</configuration>
<dependencies>
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm</artifactId>
<version>6.2</version> <!-- Use newer version of ASM -->
</dependency>
</dependencies>
</plugin>
You can find the latest at https://search.maven.org/search?q=g:org.ow2.asm%20AND%20a:asm&core=gav
add a comment |
UPDATE
The answer is now obsolete. See this answer.
maven-compiler-plugin
depends on the old version of ASM which does not support Java 10 (and Java 11) yet. However, it is possible to explicitly specify the right version of ASM:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<release>10</release>
</configuration>
<dependencies>
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm</artifactId>
<version>6.2</version> <!-- Use newer version of ASM -->
</dependency>
</dependencies>
</plugin>
You can find the latest at https://search.maven.org/search?q=g:org.ow2.asm%20AND%20a:asm&core=gav
UPDATE
The answer is now obsolete. See this answer.
maven-compiler-plugin
depends on the old version of ASM which does not support Java 10 (and Java 11) yet. However, it is possible to explicitly specify the right version of ASM:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<release>10</release>
</configuration>
<dependencies>
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm</artifactId>
<version>6.2</version> <!-- Use newer version of ASM -->
</dependency>
</dependencies>
</plugin>
You can find the latest at https://search.maven.org/search?q=g:org.ow2.asm%20AND%20a:asm&core=gav
edited Feb 13 at 21:53
palacsint
22.4k96494
22.4k96494
answered Mar 21 '18 at 5:39
ZhekaKozlovZhekaKozlov
15.7k871115
15.7k871115
add a comment |
add a comment |
Alternatively, as of 30Jul, 2018 to fix the above issue, one can configure the java version used within maven to any up to JDK/11 and make use of the maven-compiler-plugin:3.8.0
to specify a release of either 9,10,11 without any explicit dependencies.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<release>11</release> <!--or <release>10</release>-->
</configuration>
</plugin>
Note:- The default value for source/target has been lifted from 1.5 to 1.6 with this version. -- release notes.
Edit [30.12.2018]
In fact, you can make use of the same version of maven-compiler-plugin
while compiling the code against JDK/12 as well. Have shared more details and a sample configuration in how to Compile a JDK12 preview feature with Maven.
1
This only works out of the box when maven is executed with Java 11. If your platform Java version is e.g. Java 8 (and so maven is executed with Java 8), you need to define a toolchain maven.apache.org/guides/mini/guide-using-toolchains.html
– Franz Deschler
Jan 11 at 17:16
2
Note that the associated property ismaven.compiler.release
:<properties><maven.compiler.release>11</maven.compiler.release></properties>
– Olivier Grégoire
Feb 26 at 12:20
add a comment |
Alternatively, as of 30Jul, 2018 to fix the above issue, one can configure the java version used within maven to any up to JDK/11 and make use of the maven-compiler-plugin:3.8.0
to specify a release of either 9,10,11 without any explicit dependencies.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<release>11</release> <!--or <release>10</release>-->
</configuration>
</plugin>
Note:- The default value for source/target has been lifted from 1.5 to 1.6 with this version. -- release notes.
Edit [30.12.2018]
In fact, you can make use of the same version of maven-compiler-plugin
while compiling the code against JDK/12 as well. Have shared more details and a sample configuration in how to Compile a JDK12 preview feature with Maven.
1
This only works out of the box when maven is executed with Java 11. If your platform Java version is e.g. Java 8 (and so maven is executed with Java 8), you need to define a toolchain maven.apache.org/guides/mini/guide-using-toolchains.html
– Franz Deschler
Jan 11 at 17:16
2
Note that the associated property ismaven.compiler.release
:<properties><maven.compiler.release>11</maven.compiler.release></properties>
– Olivier Grégoire
Feb 26 at 12:20
add a comment |
Alternatively, as of 30Jul, 2018 to fix the above issue, one can configure the java version used within maven to any up to JDK/11 and make use of the maven-compiler-plugin:3.8.0
to specify a release of either 9,10,11 without any explicit dependencies.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<release>11</release> <!--or <release>10</release>-->
</configuration>
</plugin>
Note:- The default value for source/target has been lifted from 1.5 to 1.6 with this version. -- release notes.
Edit [30.12.2018]
In fact, you can make use of the same version of maven-compiler-plugin
while compiling the code against JDK/12 as well. Have shared more details and a sample configuration in how to Compile a JDK12 preview feature with Maven.
Alternatively, as of 30Jul, 2018 to fix the above issue, one can configure the java version used within maven to any up to JDK/11 and make use of the maven-compiler-plugin:3.8.0
to specify a release of either 9,10,11 without any explicit dependencies.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<release>11</release> <!--or <release>10</release>-->
</configuration>
</plugin>
Note:- The default value for source/target has been lifted from 1.5 to 1.6 with this version. -- release notes.
Edit [30.12.2018]
In fact, you can make use of the same version of maven-compiler-plugin
while compiling the code against JDK/12 as well. Have shared more details and a sample configuration in how to Compile a JDK12 preview feature with Maven.
edited Jan 23 at 9:53
senseiwu
2,01411333
2,01411333
answered Jul 30 '18 at 2:18
NamanNaman
44.8k11102204
44.8k11102204
1
This only works out of the box when maven is executed with Java 11. If your platform Java version is e.g. Java 8 (and so maven is executed with Java 8), you need to define a toolchain maven.apache.org/guides/mini/guide-using-toolchains.html
– Franz Deschler
Jan 11 at 17:16
2
Note that the associated property ismaven.compiler.release
:<properties><maven.compiler.release>11</maven.compiler.release></properties>
– Olivier Grégoire
Feb 26 at 12:20
add a comment |
1
This only works out of the box when maven is executed with Java 11. If your platform Java version is e.g. Java 8 (and so maven is executed with Java 8), you need to define a toolchain maven.apache.org/guides/mini/guide-using-toolchains.html
– Franz Deschler
Jan 11 at 17:16
2
Note that the associated property ismaven.compiler.release
:<properties><maven.compiler.release>11</maven.compiler.release></properties>
– Olivier Grégoire
Feb 26 at 12:20
1
1
This only works out of the box when maven is executed with Java 11. If your platform Java version is e.g. Java 8 (and so maven is executed with Java 8), you need to define a toolchain maven.apache.org/guides/mini/guide-using-toolchains.html
– Franz Deschler
Jan 11 at 17:16
This only works out of the box when maven is executed with Java 11. If your platform Java version is e.g. Java 8 (and so maven is executed with Java 8), you need to define a toolchain maven.apache.org/guides/mini/guide-using-toolchains.html
– Franz Deschler
Jan 11 at 17:16
2
2
Note that the associated property is
maven.compiler.release
: <properties><maven.compiler.release>11</maven.compiler.release></properties>
– Olivier Grégoire
Feb 26 at 12:20
Note that the associated property is
maven.compiler.release
: <properties><maven.compiler.release>11</maven.compiler.release></properties>
– Olivier Grégoire
Feb 26 at 12:20
add a comment |
Boosting your maven-compiler-plugin to 3.8.0 seems to be necessary but not sufficient. If you're still having problems, you should also make sure your JAVA_HOME environment variable is set to Java 10 (or 11) if you're running from the command line. (The error message you get won't tell you this.) Or if you're running from an IDE, you need to make sure it is set to run maven with your current JDK.
add a comment |
Boosting your maven-compiler-plugin to 3.8.0 seems to be necessary but not sufficient. If you're still having problems, you should also make sure your JAVA_HOME environment variable is set to Java 10 (or 11) if you're running from the command line. (The error message you get won't tell you this.) Or if you're running from an IDE, you need to make sure it is set to run maven with your current JDK.
add a comment |
Boosting your maven-compiler-plugin to 3.8.0 seems to be necessary but not sufficient. If you're still having problems, you should also make sure your JAVA_HOME environment variable is set to Java 10 (or 11) if you're running from the command line. (The error message you get won't tell you this.) Or if you're running from an IDE, you need to make sure it is set to run maven with your current JDK.
Boosting your maven-compiler-plugin to 3.8.0 seems to be necessary but not sufficient. If you're still having problems, you should also make sure your JAVA_HOME environment variable is set to Java 10 (or 11) if you're running from the command line. (The error message you get won't tell you this.) Or if you're running from an IDE, you need to make sure it is set to run maven with your current JDK.
answered Sep 2 '18 at 18:14
MiguelMunozMiguelMunoz
1,8641619
1,8641619
add a comment |
add a comment |
Specify maven.compiler.source and target versions.
1) Maven version which supports jdk you use. In my case JDK 11 and maven 3.6.0.
2) pom.xml
<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
As an alternative, you can fully specify maven compiler plugin. See previous answers. It is shorter in my example :)
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<release>11</release>
</configuration>
</plugin>
</plugins>
</build>
3) rebuild the project to avoid compile errors in your IDE.
4) If it still does not work. In Intellij Idea I prefer using terminal instead of using terminal from OS. Then in Idea go to file -> settings -> build tools -> maven. I work with maven I downloaded from apache (by default Idea uses bundled maven). Restart Idea then and run mvn clean install
again. Also make sure you have correct Path, MAVEN_HOME, JAVA_HOME environment variables.
I also saw this one-liner, but it does not work.
<maven.compiler.release>11</maven.compiler.release>
add a comment |
Specify maven.compiler.source and target versions.
1) Maven version which supports jdk you use. In my case JDK 11 and maven 3.6.0.
2) pom.xml
<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
As an alternative, you can fully specify maven compiler plugin. See previous answers. It is shorter in my example :)
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<release>11</release>
</configuration>
</plugin>
</plugins>
</build>
3) rebuild the project to avoid compile errors in your IDE.
4) If it still does not work. In Intellij Idea I prefer using terminal instead of using terminal from OS. Then in Idea go to file -> settings -> build tools -> maven. I work with maven I downloaded from apache (by default Idea uses bundled maven). Restart Idea then and run mvn clean install
again. Also make sure you have correct Path, MAVEN_HOME, JAVA_HOME environment variables.
I also saw this one-liner, but it does not work.
<maven.compiler.release>11</maven.compiler.release>
add a comment |
Specify maven.compiler.source and target versions.
1) Maven version which supports jdk you use. In my case JDK 11 and maven 3.6.0.
2) pom.xml
<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
As an alternative, you can fully specify maven compiler plugin. See previous answers. It is shorter in my example :)
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<release>11</release>
</configuration>
</plugin>
</plugins>
</build>
3) rebuild the project to avoid compile errors in your IDE.
4) If it still does not work. In Intellij Idea I prefer using terminal instead of using terminal from OS. Then in Idea go to file -> settings -> build tools -> maven. I work with maven I downloaded from apache (by default Idea uses bundled maven). Restart Idea then and run mvn clean install
again. Also make sure you have correct Path, MAVEN_HOME, JAVA_HOME environment variables.
I also saw this one-liner, but it does not work.
<maven.compiler.release>11</maven.compiler.release>
Specify maven.compiler.source and target versions.
1) Maven version which supports jdk you use. In my case JDK 11 and maven 3.6.0.
2) pom.xml
<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
As an alternative, you can fully specify maven compiler plugin. See previous answers. It is shorter in my example :)
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<release>11</release>
</configuration>
</plugin>
</plugins>
</build>
3) rebuild the project to avoid compile errors in your IDE.
4) If it still does not work. In Intellij Idea I prefer using terminal instead of using terminal from OS. Then in Idea go to file -> settings -> build tools -> maven. I work with maven I downloaded from apache (by default Idea uses bundled maven). Restart Idea then and run mvn clean install
again. Also make sure you have correct Path, MAVEN_HOME, JAVA_HOME environment variables.
I also saw this one-liner, but it does not work.
<maven.compiler.release>11</maven.compiler.release>
edited Mar 4 at 19:08
answered Mar 4 at 19:02
Yan KhonskiYan Khonski
4,05762752
4,05762752
add a comment |
add a comment |
It might not exactly be the same error, but I had a similar one.
Check Maven Java Version
Since Maven is also runnig with Java, check first with which version your Maven is running on:
mvn --version | grep Java
It returns:
Java version 1.8.0_151, vendor: Oracle
Corporation, runtime: C:toolsjdkopenjdk1.8
Incompatible version
Here above my maven is running with Java Version 1.8.0_151
.
So even if I specify maven to compile with Java 11
:
<properties>
<java.version>11</java.version>
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
</properties>
It will logically print out this error:
[ERROR] Failed to execute goal
org.apache.maven.plugins:maven-compiler-plugin:3.8.0:compile
(default-compile) on project efa-example-commons-task: Fatal error
compiling: invalid target release: 11 -> [Help 1]
How to set specific java version to Maven
The logical thing to do is to set a higher Java Version to Maven (e.g. Java version 11 instead 1.8).
Maven make use of the environment variable JAVA_HOME
to find the Java Version to run. So change this variable to the JDK you want to compile against (e.g. OpenJDK 11).
Sanity check
Then run again mvn --version
to make sure the configuration has been taken care of:
λ mvn --version | grep Java Java version: 11.0.2, vendor: Oracle
Corporation, runtime: C:toolsjdkopenjdk11
Which is much better and correct to compile code written with the Java 11 specifications.
add a comment |
It might not exactly be the same error, but I had a similar one.
Check Maven Java Version
Since Maven is also runnig with Java, check first with which version your Maven is running on:
mvn --version | grep Java
It returns:
Java version 1.8.0_151, vendor: Oracle
Corporation, runtime: C:toolsjdkopenjdk1.8
Incompatible version
Here above my maven is running with Java Version 1.8.0_151
.
So even if I specify maven to compile with Java 11
:
<properties>
<java.version>11</java.version>
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
</properties>
It will logically print out this error:
[ERROR] Failed to execute goal
org.apache.maven.plugins:maven-compiler-plugin:3.8.0:compile
(default-compile) on project efa-example-commons-task: Fatal error
compiling: invalid target release: 11 -> [Help 1]
How to set specific java version to Maven
The logical thing to do is to set a higher Java Version to Maven (e.g. Java version 11 instead 1.8).
Maven make use of the environment variable JAVA_HOME
to find the Java Version to run. So change this variable to the JDK you want to compile against (e.g. OpenJDK 11).
Sanity check
Then run again mvn --version
to make sure the configuration has been taken care of:
λ mvn --version | grep Java Java version: 11.0.2, vendor: Oracle
Corporation, runtime: C:toolsjdkopenjdk11
Which is much better and correct to compile code written with the Java 11 specifications.
add a comment |
It might not exactly be the same error, but I had a similar one.
Check Maven Java Version
Since Maven is also runnig with Java, check first with which version your Maven is running on:
mvn --version | grep Java
It returns:
Java version 1.8.0_151, vendor: Oracle
Corporation, runtime: C:toolsjdkopenjdk1.8
Incompatible version
Here above my maven is running with Java Version 1.8.0_151
.
So even if I specify maven to compile with Java 11
:
<properties>
<java.version>11</java.version>
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
</properties>
It will logically print out this error:
[ERROR] Failed to execute goal
org.apache.maven.plugins:maven-compiler-plugin:3.8.0:compile
(default-compile) on project efa-example-commons-task: Fatal error
compiling: invalid target release: 11 -> [Help 1]
How to set specific java version to Maven
The logical thing to do is to set a higher Java Version to Maven (e.g. Java version 11 instead 1.8).
Maven make use of the environment variable JAVA_HOME
to find the Java Version to run. So change this variable to the JDK you want to compile against (e.g. OpenJDK 11).
Sanity check
Then run again mvn --version
to make sure the configuration has been taken care of:
λ mvn --version | grep Java Java version: 11.0.2, vendor: Oracle
Corporation, runtime: C:toolsjdkopenjdk11
Which is much better and correct to compile code written with the Java 11 specifications.
It might not exactly be the same error, but I had a similar one.
Check Maven Java Version
Since Maven is also runnig with Java, check first with which version your Maven is running on:
mvn --version | grep Java
It returns:
Java version 1.8.0_151, vendor: Oracle
Corporation, runtime: C:toolsjdkopenjdk1.8
Incompatible version
Here above my maven is running with Java Version 1.8.0_151
.
So even if I specify maven to compile with Java 11
:
<properties>
<java.version>11</java.version>
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
</properties>
It will logically print out this error:
[ERROR] Failed to execute goal
org.apache.maven.plugins:maven-compiler-plugin:3.8.0:compile
(default-compile) on project efa-example-commons-task: Fatal error
compiling: invalid target release: 11 -> [Help 1]
How to set specific java version to Maven
The logical thing to do is to set a higher Java Version to Maven (e.g. Java version 11 instead 1.8).
Maven make use of the environment variable JAVA_HOME
to find the Java Version to run. So change this variable to the JDK you want to compile against (e.g. OpenJDK 11).
Sanity check
Then run again mvn --version
to make sure the configuration has been taken care of:
λ mvn --version | grep Java Java version: 11.0.2, vendor: Oracle
Corporation, runtime: C:toolsjdkopenjdk11
Which is much better and correct to compile code written with the Java 11 specifications.
edited Mar 7 at 15:19
answered Mar 7 at 15:14
KeyMaker00KeyMaker00
1,3602130
1,3602130
add a comment |
add a comment |
protected by cassiomolin Aug 8 '18 at 18:13
Thank you for your interest in this question.
Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).
Would you like to answer one of these unanswered questions instead?
@MikhailKholodkov The bug has been resolved and one can now make use of the
maven-compiler-plugin:3.8.0
to fix the above error.– Naman
Jul 30 '18 at 2:29