I am trying to compile my project with Java 11.
When I try to run the application with Java 8 as the Java version in pom.xml, it works fine. But when I try to run it with Java 11, it throws an error.
Fatal error compiling: invalid target release: 11
I’ve tried to fix it in various ways, like changing the environment variable, updating the path, and pointing %JAVA_HOME% to Java 11.
The commands and their results as on my computer are as follows:
java -version
echo %JAVA_HOME%
Output:
java version "11.0.8" 2020-07-14 LTS
C:Program FilesJavajdk-11.0.8
I am using IntelliJ IDEA and have made the necessary changes as suggested in this tutorial.
My pom.xml file looks something like this:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.0.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>demo</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>11</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>com.google.cloud.tools</groupId>
<artifactId>appengine-maven-plugin</artifactId>
<version>2.2.0</version>
<configuration>
<version>1</version>
<projectId>businessapplication-6963d</projectId>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<source>11</source>
<target>11</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
When I check the Maven version, it shows JDK 1.8 as the Java version:
mvn --version
Output:
Java version: 1.8.0_241, vendor: Oracle Corporation, runtime: C:Program FilesJavajdk1.8.0_241jre
How can I point Maven to Java 11? Or, if that is not the problem, how to solve this issue? I don’t think that this question is a duplicate of invalid target release: 1.7, as I have already implemented the solutions provided in that thread.
Error after building the project:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.0:compile (default-compile) on project demo: Fatal error compiling: invalid target release: 11 -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[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
The path environment variable is:
C:Program Files (x86)Common FilesIntelShared FilescppbinIntel64;
C:Program Files (x86)InteliCLS Client;
C:Program FilesInteliCLS Client;
C:WINDOWSsystem32;C:WINDOWS;
C:WINDOWSSystem32Wbem;
C:WINDOWSSystem32WindowsPowerShellv1.0;
C:Program Files (x86)IntelIntel(R) Management Engine ComponentsDAL;
C:Program FilesIntelIntel(R) Management Engine ComponentsDAL;
C:Program Files (x86)IntelIntel(R) Management Engine ComponentsIPT;
C:Program FilesIntelIntel(R) Management Engine ComponentsIPT;C:WINDOWSSystem32OpenSSH;
C:Delhi 2.0apache-maven-3.6.1bin;
C:Program FilesJavajdk-11.0.8bin;C:Program FilesIntelWiFibin;
C:Program FilesCommon FilesIntelWirelessCommon;
C:Program FilesGitcmd;D:Flutterflutterflutterbin;
C:UsersInfinity97AppDataLocalGoogleCloud SDKgoogle-cloud-sdkbin;
C:UsersInfinity97AppDataLocalMicrosoftWindowsApps;
C:Program FilesJetBrainsIntelliJ IDEA Community Edition 2019.2bin;
H:apache-maven-3.6.3bin;
C:Program FilesPostgreSQL12bin;
C:Program FilesPostgreSQL12lib;
C:Program FilesDocker Toolbox
Ошибка «invalid target release» возникает при попытке компилятором Java скомпилировать исходные файлы с неизвестной для него версией Java. В подавляющем большинстве случаев ошибка возникает оттого, что у вас в системе установлена и запускается Java более старой версии, чем та версия Java, которая требуется для компиляции исходных файлов.
Случаи, в которые вы можете натолкнуться на ошибку «Invalid target release»:
Maven error — Fatal error compiling: invalid target release
Вы хотите собрать мавеновский проект, в pom.xml у вас указана более новая версия Java, а в системе установлена более старая версия:

В данном случае в системе установлена JDK 8, а в pom.xml указана Java 12.
Решение проблемы
В данном случае вам нужно либо обновить свой JDK до более нового, либо понизить требуемую версию в файле pom.xml до той, что у вас установлена в системе.
Итак, у вас есть проект, открытый в вашей любимой IDE. Возьмём для примера IntelliJ Idea. Возможно, вы создали проект в Idea, импортировав pom.xml или build.gradle, а возможно, вы создали этот проект с нуля.
В операционной системе у вас установлена JDK 8 и в настройках Idea подключена именно эта версия. Но в настройках проекта Idea или в файле pom.xml указана версия JDK 12 (или более новая).
В этом случае, при попытке собрать проект, вы увидите лишь ошибку о неправильной версии:

Error:java: invalid source release: 12
Решение проблемы
Первый вариант решения проблемы это установить более новую версию JDK и указать её в настройках IntelliJ Idea
Второй вариант решения данной ошибки – понизить версию в свойствах проекта или в pom.xml / build.gradle. Примечание: обычно это менее приемлемый вариант, чем установка более поздней JDK. Предпочтительнее установить в системе более новую JDK.
Ошибка «Invalid target release» в компиляторе
Гораздо менее распространённый, но вполне допустимый вариант – вы компилируете исходники, напрямую вызывая компилятор Java javac. Причина проблемы здесь та же – более старый компилятор не знает о существовании более новой версии Java, под которую вы хотите скомпилировать байт код.
Решение проблемы
Сначала проверьте версию компилятора:
javac -version
Затем проверьте, какую версию вы указываете с помощью опции -target.
Если версия компилятора ниже запрашиваемой версии, вам нужно либо передавать в опции компилятора более низкую версию, либо обновить JDK.
Ошибка «Invalid target release» при указании несуществующей версии Java
Вполне возможен вариант, при котором у вас в скрипте сборки проекта указана несуществующая версия Java. Вам лишь нужно удостовериться, что вы указали корректную версию Java.
Issue
I’m trying to push my Spring boot app to Heroku, but i’m get this error below.
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 41 source files to /tmp/build_4ad2779b666eb1cd25b32f96d104b00b/target/classes
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 11.273 s
[INFO] Finished at: 2020-03-23T14:23:48Z
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project algamoney-api: Fatal error compiling: invalid target release: 11 -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[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
! ERROR: Failed to build app with Maven
We’re sorry this build is failing! If you can’t find the issue in application code,
please submit a ticket so we can help: https://help.heroku.com/
! Push rejected, failed to compile Java app.
! Push failed
I checked the JAVA_HOME, java -version, java -version and mvn -version all points to the same java version: 11.0.3
My POM.xml:
<?xml version="1.0" encoding="UTF-8"?>
https://maven.apache.org/xsd/maven-4.0.0.xsd»>
4.0.0
org.springframework.boot
spring-boot-starter-parent
2.2.5.RELEASE
com.hugo.algamoney-api
algamoney-api
1.0.0-SNAPSHOT
algamoney-api
Workshop Spring Boot com mongodb
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-core</artifactId>
</dependency>
<!-- Dependencia do hibernate e Jackson para funcionar o datatype -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-java8</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
</dependency>
<!-- Pega a causa da exceção -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-jpamodelgen</artifactId>
<scope>provided</scope>
</dependency>
<!-- Spring security -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security.oauth</groupId>
<artifactId>spring-security-oauth2</artifactId>
<version>2.3.5.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-jwt</artifactId>
<version>1.0.10.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>com.heroku.sdk</groupId>
<artifactId>heroku-maven-plugin</artifactId>
<version>2.0.8</version>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<release>11</release>
</configuration>
</plugin>
</plugins>
</build>
Solution
problem solved! After a lot of try and error it works, i will post below the steps that i take:
- Change the entire project to java 11, for some reassy the JRE of the project whas in the 1.8 version;
- Create a
system.propertieswhitch the follow Configuration:java.runtime.version=11.0.3; - Commit and add push again to heroku;
Answered By — Hugo Feijó
Hello Guys, How are you all? Hope You all Are Fine. Today When I am trying to run my project with java 11 I am facing following error Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.0:compile (default-compile) on project demo: Fatal error compiling: invalid target release: 11 in java. So Here I am Explain to you all the possible solutions here.
Without wasting your time, Let’s start This Article to Solve This Error.
Contents
- How This Error Occurs ?
- How To Solve Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.0:compile (default-compile) on project demo: Fatal error compiling: invalid target release: 11 Error ?
- Solution 1: add this line in pom.xml
- Solution 2: set JAVA_HOME
- Solution 3: add java version in pom.xml
- Solution 4: Check JRE version
- Summary
How This Error Occurs ?
When I am trying to run my project with java 11 I am facing following error.
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.0:compile (default-compile) on project demo: Fatal error compiling: invalid target release: 11 -> [Help 1] [ERROR] [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. [ERROR] Re-run Maven using the -X switch to enable full debug logging.
[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
- How To Solve Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.0:compile (default-compile) on project demo: Fatal error compiling: invalid target release: 11 Error ?
To Solve Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.0:compile (default-compile) on project demo: Fatal error compiling: invalid target release: 11 Error before calling maven, try using set JAVA_HOME=C:pathtojdk11 on the first line and your error must be solved. Second solution is Just check the JRE in use for Maven. First of all Run Configurations. Then, Select your Maven Build configuration. Now, Click the JRE tab and choose the JRE version in accordance with your POM.
- Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.0:compile (default-compile) on project demo: Fatal error compiling: invalid target release: 11
To Solve Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.0:compile (default-compile) on project demo: Fatal error compiling: invalid target release: 11 Error before calling maven, try using set JAVA_HOME=C:pathtojdk11 on the first line and your error must be solved. Second solution is Just check the JRE in use for Maven. First of all Run Configurations. Then, Select your Maven Build configuration. Now, Click the JRE tab and choose the JRE version in accordance with your POM.
Solution 1: 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>
Solution 2: set JAVA_HOME
before calling maven, try using set JAVA_HOME=C:pathtojdk11 on the first line and your error must be solved.
Solution 3: add java version in pom.xml
add java version in pom.xml. add this follow code in your pom file.
<properties>
<java.version>1.8</java.version>
</properties>
Solution 4: Check JRE version
Just check the JRE in use for Maven.
First of all Run Configurations.
Then, Select your Maven Build configuration.
Now, Click the JRE tab and choose the JRE version in accordance with your POM.
Summary
It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you?
Also, Read
- java.lang.NoClassDefFoundError: Could not initialize class org.codehaus.groovy.vmplugin.v7.Java7
— Update —
Found that using InterlliJ can compile successfully without module-info.java. but failed to compile with it. Anyone have any idea?
— Original Answer —
Environment:
- Java 11
- Maven 3.6.0
- Vert.x 3.6.3
- maven-compiler-plugin: 3.8.0
Setting:
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<source>11</source>
<target>11</target>
<useIncrementalCompilation>false</useIncrementalCompilation>
<encoding>UTF-8</encoding>
<generatedSourcesDirectory>src/main/generated</generatedSourcesDirectory>
<generatedTestSourcesDirectory>src/test/generated</generatedTestSourcesDirectory>
<annotationProcessorPaths>
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-codegen</artifactId>
<version>3.6.0</version>
</dependency>
</annotationProcessorPaths>
</configuration>
...
</plugin>
Problem:
Run ./mvnw compile to compile the Data Class with @DataObject(generateConverter = true) the error invalid target release: 11 occurs.
The module-info.java:
module wonderland {
requires vertx.codegen;
requires vertx.core;
}
package-info.java
@ModuleGen(name = "wonderland-module", groupPackage = "com.ra.wonderland.module")
package com.ra.wonderland.module;
import io.vertx.codegen.annotations.ModuleGen;
Error:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.0:compile (default-compile) on project Wonderland: Fatal error compiling: invalid target release: 11 -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.0:compile (default-compile) on project Wonderland: Fatal error compiling
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:956)
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)
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.apache.maven.wrapper.BootstrapMainStarter.start (BootstrapMainStarter.java:39)
at org.apache.maven.wrapper.WrapperExecutor.execute (WrapperExecutor.java:122)
at org.apache.maven.wrapper.MavenWrapperMain.main (MavenWrapperMain.java:50)
Caused by: org.apache.maven.plugin.MojoExecutionException: Fatal error compiling
at org.apache.maven.plugin.compiler.AbstractCompilerMojo.execute (AbstractCompilerMojo.java:1140)
at org.apache.maven.plugin.compiler.CompilerMojo.execute (CompilerMojo.java:188)
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:956)
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)
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.apache.maven.wrapper.BootstrapMainStarter.start (BootstrapMainStarter.java:39)
at org.apache.maven.wrapper.WrapperExecutor.execute (WrapperExecutor.java:122)
at org.apache.maven.wrapper.MavenWrapperMain.main (MavenWrapperMain.java:50)
Caused by: org.codehaus.plexus.compiler.CompilerException: invalid target release: 11
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:1129)
at org.apache.maven.plugin.compiler.CompilerMojo.execute (CompilerMojo.java:188)
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:956)
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)
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.apache.maven.wrapper.BootstrapMainStarter.start (BootstrapMainStarter.java:39)
at org.apache.maven.wrapper.WrapperExecutor.execute (WrapperExecutor.java:122)
at org.apache.maven.wrapper.MavenWrapperMain.main (MavenWrapperMain.java:50)
Caused by: java.lang.IllegalArgumentException: invalid target release: 11
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:1129)
at org.apache.maven.plugin.compiler.CompilerMojo.execute (CompilerMojo.java:188)
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:956)
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)
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.apache.maven.wrapper.BootstrapMainStarter.start (BootstrapMainStarter.java:39)
at org.apache.maven.wrapper.WrapperExecutor.execute (WrapperExecutor.java:122)
at org.apache.maven.wrapper.MavenWrapperMain.main (MavenWrapperMain.java:50)
Problem
You may encounter the following error when running a Maven build:
Fatal error compiling: invalid target release: <JDK_VERSION>
Solution
Below three ways to solve the problem:
- Adding the environment variable JAVA_HOME
- Using Maven on Eclipse
- Configure your pom.xml by forking the maven-compiler-plugin
1- Adding the environment variable JAVA_HOME
This problem is due to the fact that the environment variable JAVA_HOME and the target property of the maven-compiler-plugin point to a different JDK versions. The easy solution will be to fill JAVA_HOME with the correct value.
To verify that, open the pom.xml file of your project and check the target property of the maven-compiler-plugin. For example
|
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.1</version> <configuration> <source>1.7</source> <target>1.7</target> <encoding>UTF-8</encoding> </configuration> </plugin> |
The target property points to JDK version 1.7.
Let’s see the value of the JAVA_HOME environment variable used by Maven. Open a prompt command and execute the following command:
Output
Output of mvn -version
The JAVA_HOME points to a JDK 1.6 and this is why Maven throws the exception: invalid target release. You must set the value of JAVA_HOME to the correct JDK 1.7 home directory. Below how to perform it:
On windows
- Go to System properties -> Advanced system settings -> Advanced -> environment variable and on the System variables section select JAVA_HOME and click on Edit
- Fill the form with the following
Variable name: JAVA_HOME
Variable value: <PATH_TO_JDK_HOME>
Setting the environment variable JAVA_HOME
If you are using command line you can set the variable before running the build as following:
|
set JAVA_HOME=<PATH_TO_JDK_HOME> |
The default location in Windows is : C:Program FilesJavajdk1.7.x_xx
On Unix
|
export JAVA_HOME=/usr/java/jdk1.7.0_79/bin/java |
On Mac
in ~/.profile:
|
export JAVA_HOME=$(/usr/libexec/java_home —v 1.7) |
2- Using Maven on Eclipse
Another solution if you are using Maven on Eclipse IDE is to set the correct JDK in your Maven configuration:
- On your Eclipse IDE, Click on Run As… -> Run Configurations…
- Select your Maven Build or create a new one
- And on the JRE tab, check in the Runtime JRE section that you are using the correct JDK. If not, click Installed JREs… and add the adequate one.
- Click Apply
3- Setting the correct compiler in the Maven-compiler-plugin
Another solution is to fork the maven-compiler-plugin and set the full path to the correct Java compiler as below:
|
<plugin> <artifactId>maven—compiler—plugin</artifactId> <version>3.1</version> <configuration> <source>1.7</source> <target>1.7</target> <verbose>true</verbose> <fork>true</fork> <executable>C:Program FilesJavajdk1.7.0_79binjavac</executable> </configuration> </plugin> |
References
- Importance of JAVA_HOME in Apache Maven
- Maven-compiler-plugin : compile-using-different-jdk
I’ve recently upgraded Java from 1.8 to 11.
mvn -version
Maven home: /usr/share/maven
Java version: 11.0.4, vendor: Ubuntu, runtime: /usr/lib/jvm/java-11-openjdk-amd64
Default locale: en_NZ, platform encoding: UTF-8
OS name: "linux", version: "5.0.0-37-generic", arch: "amd64", family: "unix"
javac -version
javac 11.0.4
java -version
openjdk version "11.0.4" 2019-07-16
OpenJDK Runtime Environment (build 11.0.4+11-post-Ubuntu-1ubuntu218.04.3)
OpenJDK 64-Bit Server VM (build 11.0.4+11-post-Ubuntu-1ubuntu218.04.3, mixed mode, sharing)
echo $JAVA_HOME
/usr/lib/jvm/default-java/
I am running a Maven project that was configured on 1.8.
I’m trying to build it with 11 and get the following errors:
[ERROR] Failed to execute goal org.apache.maven.plugins:
maven-compiler-plugin:3.8.1:compile (default-compile) on project server:
Fatal error compiling: invalid target release: 11 -> [Help 1]
I tried adding
<maven.compiler.release>11</maven.compiler.release>
Which results in invalid flag: --release
My POM
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>co.example.server</groupId>
<artifactId>example-server</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Server</name>
<description>SApplication Server</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.1.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>11</java.version>
<lombok.version>1.18.10</lombok.version>
<jjwt.version>0.9.1</jjwt.version>
<frontend-maven-plugin.version>1.6</frontend-maven-plugin.version>
</properties>
<dependencies>
<!-- Spring -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-websocket</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-messaging</artifactId>
</dependency>
<!-- Security -->
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt</artifactId>
<version>${jjwt.version}</version>
</dependency>
<!-- Data -->
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
<!-- Test -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-properties-migrator</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>
<!-- Misc -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<version>${frontend-maven-plugin.version}</version>
<executions>
<execution>
<id>Install Node and Yarn</id>
<goals>
<goal>install-node-and-yarn</goal>
</goals>
</execution>
<execution>
<id>yarn install</id>
<goals>
<goal>yarn</goal>
</goals>
<configuration>
<arguments>install</arguments>
</configuration>
</execution>
<execution>
<id>Frontend production build</id>
<goals>
<goal>yarn</goal>
</goals>
<configuration>
<arguments>run build</arguments>
</configuration>
</execution>
</executions>
<configuration>
<nodeVersion>v9.2.0</nodeVersion>
<yarnVersion>v1.5.1</yarnVersion>
<installDirectory>.mvn</installDirectory>
<workingDirectory>src/main/app</workingDirectory>
</configuration>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
<executions>
<execution>
<id>Copy frontend production build to resources</id>
<phase>generate-resources</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${basedir}/target/classes/static</outputDirectory>
<resources>
<resource>
<directory>src/main/app/build/</directory>
<filtering>true</filtering>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.6.201602180812</version>
<executions>
<execution>
<id>prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.eluder.coveralls</groupId>
<artifactId>coveralls-maven-plugin</artifactId>
<version>4.3.0</version>
<configuration>
<repoToken>${env.COVERALLS_REPO_TOKEN}</repoToken>
</configuration>
</plugin>
</plugins>
</build>
</project>


