Maven: Invalid target release: 10
Asked Answered
P

12

79

I'm trying to compile my maven project using Java 10 but I'm having trouble. In my IDE (IntelliJ IDEA) everything compiles and runs just fine under Java 10. I installed the latest maven version 3.5.4 and pointed my JAVA_HOME to the JDK 10:

$ mvn --version
Apache Maven 3.5.4 (1edded0938998edf8bf061f1ceb3cfdeccf443fe; 2018-06-17T20:33:14+02:00)
Maven home: C:\Maven\bin\..
Java version: 10.0.2, vendor: Oracle Corporation, runtime: C:\Program Files\Java\jdk-10.0.2
Default locale: en_US, platform encoding: Cp1252
OS name: "windows 10", version: "10.0", arch: "amd64", family: "windows"

The maven command I use is:

mvn package -Dmaven.test.skip

In my pom.xml I had the following for Java 8 which worked fine:

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
    <libraries.directory>libraries</libraries.directory>
</properties>

For Java 10 I changed it to the following:

<maven.compiler.source>10</maven.compiler.source>
<maven.compiler.target>10</maven.compiler.target>

This does not work, just like using 1.10 as the version for the source and target compiler.

The full debug logging output (-X command line switch) is the following:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.7.0:compile (default-compile) on project My-Project: Fatal error compiling: invalid target release: 1.10 -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.7.0:compile (default-compile) on project My-Project: Fatal error compiling
    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: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:954)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:288)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:192)
    at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:498)
    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.MojoExecutionException: Fatal error compiling
    at org.apache.maven.plugin.compiler.AbstractCompilerMojo.execute (AbstractCompilerMojo.java:1086)
    at org.apache.maven.plugin.compiler.CompilerMojo.execute (CompilerMojo.java:168)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:208)
    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: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:954)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:288)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:192)
    at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:498)
    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.codehaus.plexus.compiler.CompilerException: invalid target release: 1.10
    at org.codehaus.plexus.compiler.javac.JavaxToolsCompiler.compileInProcess (JavaxToolsCompiler.java:173)
    at org.codehaus.plexus.compiler.javac.JavacCompiler.performCompile (JavacCompiler.java:174)
    at org.apache.maven.plugin.compiler.AbstractCompilerMojo.execute (AbstractCompilerMojo.java:1075)
    at org.apache.maven.plugin.compiler.CompilerMojo.execute (CompilerMojo.java:168)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:208)
    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: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:954)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:288)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:192)
    at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:498)
    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: java.lang.IllegalArgumentException: invalid target release: 1.10
    at com.sun.tools.javac.main.OptionHelper$GrumpyHelper.error (OptionHelper.java:103)
    at com.sun.tools.javac.main.Option$12.process (Option.java:216)
    at com.sun.tools.javac.api.JavacTool.processOptions (JavacTool.java:217)
    at com.sun.tools.javac.api.JavacTool.getTask (JavacTool.java:156)
    at com.sun.tools.javac.api.JavacTool.getTask (JavacTool.java:107)
    at com.sun.tools.javac.api.JavacTool.getTask (JavacTool.java:64)
    at org.codehaus.plexus.compiler.javac.JavaxToolsCompiler.compileInProcess (JavaxToolsCompiler.java:125)
    at org.codehaus.plexus.compiler.javac.JavacCompiler.performCompile (JavacCompiler.java:174)
    at org.apache.maven.plugin.compiler.AbstractCompilerMojo.execute (AbstractCompilerMojo.java:1075)
    at org.apache.maven.plugin.compiler.CompilerMojo.execute (CompilerMojo.java:168)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:208)
    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: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:954)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:288)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:192)
    at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:498)
    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)
[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/MojoExecutionException

Adding the maven-compiler-plugin like suggested in this answer also does not work:

Fatal error compiling: invalid flag: --release -> [Help 1]

Any ideas on how to fix this problem?

Panne answered 22/7, 2018 at 19:25 Comment(5)
This was fixed in maven-compiler-plugin version 3.7.1. See issues.apache.org/jira/browse/MCOMPILER-332Metal
@Metal Interesting but maven central does not have version 3.7.1 yet so it isn't found: mvnrepository.com/artifact/org.apache.maven.plugins/…Panne
When you run with -X do you see Using compiler 'javac'. and what does it show for Command line options:?Patmore
The log reads failure when the incorrect version is specified. Make sure <release>10<release> instead of 1.10. Share the logs with 10, to see what the actual failure is.Busyness
@Panne mvnrepository is not Central. This can be found here: search.maven.orgPeristalsis
S
53

Same problem fixed for me by setting JAVA_HOME environment variable to point to the JDK with right version.

My source and destination java version in maven-compiler-plugin were 11, java -version was also on version 11, but my JAVA_HOME was pointing to JDK-1.8.

Check JAVA_HOME again by using a terminal instead of IDE:

Linux:
echo $JAVA_HOME

Win:
echo %JAVA_HOME%

Then Build your project in the same terminal:

mvn clean package
Swine answered 20/5, 2020 at 10:31 Comment(1)
This worked for me also. Go to Environment Variable on Windows then System Variables and edit the PATH variable with the Java JDK PathDiapason
P
31

This worked for me:

<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>

This answer says you need:

<dependencies>
    <dependency>
        <groupId>org.ow2.asm</groupId>
        <artifactId>asm</artifactId>
        <version>6.2</version> <!-- Use newer version of ASM -->
    </dependency>
</dependencies>

inside the <plugin/> tag, but the newer mvn (3.5.4) must obviate that, since I didn't need it.

Patmore answered 22/7, 2018 at 20:30 Comment(9)
Regardless of the dependency added or not, I still get Fatal error compiling: invalid flag: --release -> [Help 1]. javac -help says --release <release> Compile for a specific VM version. Supported targets: 10, 6, 7, 8, 9.Panne
@Panne Interesting. Do you still have the <maven.compiler..../> stuff in your pom.xml? You shouldn't need that.Patmore
If I take the two <maven.compiler....> lines out or not does not matter, still the same error...Panne
The simple thing is you should use <maven.compiler.release>9</maven.compiler.release> instead of <maven.compiler.source>..</maven.compiler.sources> and <maven.compiler.target>..</maven.compiler.target> starting with JDK 9 cause JDK 8 does has a --release option...Peristalsis
@Peristalsis Except 10, since OP is using JDK 10.Patmore
maven-compiler-plugin=3.7.0 + release=10 worked like a charm.Candiecandied
Changing JAVA_HOME may also be necessary: https://mcmap.net/q/110385/-unable-to-compile-simple-java-10-java-11-project-with-mavenDior
for java version from 1.6 to 1.10: <java.version>1.x</java.version> is fine. But for 11, it should be "11" rather than "1.11".Dominickdominie
@karlli I don't know if that happens to work, but for 9 and 10 it should be 9 and 10, not 1.9 and 1.10.Patmore
C
18

Get your java version by running java -version.

You'll get a output like :

java version "1.8.0_201"

Now go to your POM file and update source and target properities of maven-compiler-plugin with your installed java version. In my case it's 1.8

<plugin>
   <groupId>org.apache.maven.plugins</groupId>
   <artifactId>maven-compiler-plugin</artifactId>
   <configuration>
      <source>1.8</source>
      <target>1.8</target>
   </configuration>
</plugin>
Cosmorama answered 28/5, 2019 at 11:59 Comment(1)
Good hint about checking the installed Java version but the question was rather about using Java 10 and not reverting it back to 8.Panne
P
14

I had a similar problem with spring boot and java 11. I solved it by defining the following property in my pom

<maven.compiler.release>11</maven.compiler.release>

Might be useful for someone in the future.

Phyfe answered 12/9, 2019 at 8:24 Comment(3)
Adding <maven.compiler.release>11</maven.compiler.release> as property or and adding <release>11</release> as configuration to maven-compiler-plugin gives exactly the same result. Plugin documentation for releaseTeletype
Also make sure using mvn --version that you run at least Maven: 3.6.0 which uses underneath at least Java 9. There is no "--release" option for older versions.Kummerbund
This tag maven.compiler.release replaces the maven.compiler.source & maven.compiler.target tags. Comment-out the source & target lines if present when using the release tag.Sidelight
L
10

This means you are using java.version 10 which you have not installed.

<properties>
    <java.version>10</java.version>
</properties>
Lingulate answered 4/10, 2019 at 7:47 Comment(0)
B
6

As you are using Intellij, you need to follow below steps (Here I'm using Java 11, but the same applies to Java 10 and other versions as well)-

  1. Change SDK under Project Structure to Java 11

enter image description here

enter image description here

  1. Change language level for modules (if needed) under Project Structure

enter image description here

  1. Change JRE under runner in settings

enter image description here

  1. Change Target bytecode version under Java compiler in Settings

enter image description here

  1. Check maven version under Maven in settings for supporting Java 11 enter image description here

  2. In your pom, mention the version as follows, you can ignore the encoding tag here

enter image description here

  1. Lastly confirm your run configuration before building project

enter image description here

  1. If you are using Windows machine, then change environment variables JAVA_HOME, Path and MAVEN_HOME accordingly.
Berny answered 1/10, 2021 at 18:30 Comment(0)
T
6

Check your JAVA_HOME version. It seems your java version in JAVA_HOME and in POM is different. Set JAVA_HOME path properly by editing in Environment variable in Windows.

Talkie answered 12/10, 2021 at 4:54 Comment(0)
A
1

Sometimes it's just your java version. For example, when the project uses Java 10 but your Java Path is set to 8, etc. Try running java -version and make sure it's the same as your project. If not, fix it and try again.

Admire answered 10/1, 2020 at 10:46 Comment(0)
A
1

thanks to the answer above, You are using 10, i use 11, but i guess the steps are similar.

the whole point for me is to explicitly specify the version as java 11 in my pom.xml, and I solved the problem by taking the following steps.

  1. open terminal and input: java -version, then i got 1.8, and i went to .bash_profile to switch the java version to 11.2 as i have multiple java version installed. please remember "restart" your terminal and check your java version again to confirm switch is successful.

  2. Then i went to File -> Project Structure to make sure my IntelliJ using the same version as my env, which is 11.2.

  3. RESTART your Intellij, mvn clean install, solved, hope this could help someone with this issue, thanks.

Arie answered 13/1, 2021 at 1:53 Comment(0)
A
0

In "File >> Project Structure >> Project Settings >> Project >> Project SDK" choose the version of your Java installed and click OK.

It solved my Maven problem:

Invalid Target Release: 16 .

Image

Ardoin answered 7/9, 2021 at 21:9 Comment(1)
Please provide additional details in your answer. As it's currently written, it's hard to understand your solution.Makepeace
F
0

In my case I just went to terminal then I typed java -version then pressed enter. That gave me my java version which was 1.8 then I went to right click on my project folder then I clicked open POM. Then in the pom file there was this code

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

I just changed the 17 to 1.8 like this

<properties>
        <java.version>1.8</java.version>
    </properties>

I saved and I closed the IDE opened again run my program then all was fine I hope that helps.

Fortissimo answered 14/6, 2022 at 16:38 Comment(0)
E
0

Solution : add this line in pom.xml

You need to add your own context in pom.xml.

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <configuration>
        <source>1.8</source>
        <target>1.8</target>
    </configuration>
</plugin>
Electrotype answered 25/7, 2022 at 9:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.