简体   繁体   中英

Maven 3.8.0 Compiler - Fatal error compiling: release version 11 not supported

I'm unable to build using Java 11 with the latest version of the maven-compiler-plugin.

pom.xml:

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

when I try to build using Maven:

➜  mvn clean compile
[INFO] Scanning for projects...
[INFO] 
[INFO] ------------------------------------------------------------------------
[INFO] Building service 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-compiler-plugin:3.8.0:compile (default-compile) @ service ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 80 source files to /home/mip/service/target/classes
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.859 s
[INFO] Finished at: 2018-08-01T11:20:55+01:00
[INFO] Final Memory: 32M/124M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.0:compile (default-compile) on project service: Fatal error compiling: release version 11 not supported -> [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

Here are the Maven and Java versions which I am using:

➜  mvn -version
Apache Maven 3.5.2
Maven home: /usr/share/maven
Java version: 10.0.1, vendor: Oracle Corporation
Java home: /usr/lib/jvm/java-11-openjdk-amd64
Default locale: en_GB, platform encoding: UTF-8
OS name: "linux", version: "4.15.0-29-generic", arch: "amd64", family:     "unix"
➜  /usr/lib/jvm/java-11-openjdk-amd64/bin/java -version
openjdk version "10.0.1" 2018-04-17
OpenJDK Runtime Environment (build 10.0.1+10-Ubuntu-3ubuntu1)
OpenJDK 64-Bit Server VM (build 10.0.1+10-Ubuntu-3ubuntu1, mixed mode)

Could Java 11 identifying itself as "10.0.1" be causing the problem? If I modify my pom.xml to <release>10</release> then it builds with no issue, even though I do not have Java 10 installed.

➜  ~ /usr/lib/jvm/java-11-openjdk-amd64/bin/javac -version
javac 10.0.1 

➜ javac --release 11 SomeClass.java
javac: release version 11 not 
supported Usage: javac <options> <source files>
use --help for a list of possible options

I think this is an issue with the Ubuntu openjdk-11-jdk package:

➜  ~ sudo apt install openjdk-11-jdk
Reading package lists... Done
Building dependency tree       
Reading state information... Done
openjdk-11-jdk is already the newest version (10.0.1+10-3ubuntu1).
0 to upgrade, 0 to newly install, 0 to remove and 2 not to upgrade.

mvn need JAVA_HOME to be set. I faced the same issue and setting up JAVA_HOME to correct JDK did the trick.

I encountered this error while building a java project in a docker container. It must've had something to do with the way maven was installed, because it went away when I based my container on the official maven image .

Particularly, this meant using the following in my Dockerfile:

FROM maven:3.6.3-jdk-11-slim

Upon further investigation, the crucial difference is that I had the package java-11-openjdk , but I needed java-11-openjdk-devel .

For me, this came from having a Java 11 JRE installed and not a JDK. The folder name had "jdk" in it, so I assumed it was correct, but looking in the /bin folder I didn't see a javac executable, so I think it was falling back to the default Java on the system which was earlier than Java 11.

I see you are using Java 9, to be build with Java 11, please try the below:

  1. Ensure JAVA_HOME is set to C:\\Program Files\\Java\\jdk-11......

  2. In your pom.xml add "<properties> <java.version>11</java.version> </properties>" and reference ${java.version} where applicable.

  3. "mvn -v" should output something like this (depending where your maven and java installations sit in your machine): Apache Maven 3.6.1 (d66c9c0b3152b2e69ee9bac180bb8fcc8e6af555; 2019-04-04T21:00:29+02:00) Maven home: C:\\Program Files (x86)\\Apache-Maven-3.6.1\\bin.. Java version: 11.0.6, vendor: Oracle Corporation, runtime: C:\\Program Files\\Java\\jdk-11.0.6 Default locale: en_US, platform encoding: Cp1252 OS name: "windows 10", version: "10.0", arch: "amd64", family: "windows"

  4. Then retry mvn clean install

  5. If no luck, please share your pom.xml so that we can see the configuration that may be throwing your build off.

In terminal:

mvn -version

Examples - Java version: 9.0.4

Further used plugin:

<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<release>9.0.4</release>
</configuration>
</plugin>
</plugins>

I faced similar issue in centOS 7.

Fatal error compiling: error: release version 11 not supported

I was having jre but missing jdk. You can figure this out by running javac command. It is says command not found then there is need to install jdk.

To install Java 11 JDK

sudo yum install java-11-openjdk-devel

To install Java 11 JRE

sudo yum install java-11-openjdk

More details here. I found this useful.

https://phoenixnap.com/kb/install-java-on-centos

For me a deceivingly similar error, specifically java.lang.AssertionError

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project nospringboot: Fatal error compiling: java.lang.AssertionError: Version '14' not supported -> [Help 1] 

occurred because of one of the dependencies. I've replaced

<groupId>org.testifyproject.mock</groupId>
<artifactId>mockito</artifactId>
<version>1.0.6</version>

with

<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.9.5</version>

and it's working. I realised this when I ran maven build in verbose mode and it printed this output:

Caused by: java.lang.AssertionError: Version '14' not supported
    at org.testifyproject.processor.DiscoverableProcessor.getSupportedSourceVersion(DiscoverableProcessor.java:67)
    at jdk.compiler/com.sun.tools.javac.processing.JavacProcessingEnvironment$ProcessorState.checkSourceVersionCompatibility(JavacProcessingEnvironment.java:764)
    at jdk.compiler/com.sun.tools.javac.processing.JavacProcessingEnvironment$ProcessorState.<init>(JavacProcessingEnvironment.java:704)
    at jdk.compiler/com.sun.tools.javac.processing.JavacProcessingEnvironment$DiscoveredProcessors$ProcessorStateIterator.next(JavacProcessingEnvironment.java:830)
    at jdk.compiler/com.sun.tools.javac.processing.JavacProcessingEnvironment.discoverAndRunProcs(JavacProcessingEnvironment.java:926)
    at jdk.compiler/com.sun.tools.javac.processing.JavacProcessingEnvironment$Round.run(JavacProcessingEnvironment.java:1270)
...

which shows which method (in which specific package : org.testifyproject.processor.DiscoverableProcessor.getSupportedSourceVersion(DiscoverableProcessor.java:67 ) produced the negative assertion.

as the message specify, this is a version problem, i bootstrap a spring project and i selected java 11 when i actually had java 8 on my pc. i simply went bach to re-create my project with the approriate java veersion and the error went away

If you get this error in Eclipse, try compiling your project outside Eclipse after downloading and setting up the latest Maven version (including setting up MAVEN_HOME environement variable to your installation path).

If your project compiles outside Eclipse but not inside, then check the jdk used by your Maven configuration:

  • In Eclipse: Run | Run Configurations...
  • Select your Maven Build configuration
  • Select the JRE tab and make sure the right JRE is used.
  • Repeat for your other Maven configurations

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM