简体   繁体   中英

Unable to build Java project targeting JDK 11, Invalid target release 11

I have JDK 11 installed along with Maven 3.6.2 and am using error prone to compile my Java maven projects. With this configuration:

pom.xml:

<properties>
  <java.version>11</java.version>
  <maven.compiler.source>${java.version}</maven.compiler.source>
  <maven.compiler.target>${java.version}</maven.compiler.target>
</properties>

pom.xml:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>${maven.compiler.plugin.version}</version>
    <configuration>
        <compilerId>javac-with-errorprone</compilerId>
        <forceJavacCompilerUse>true</forceJavacCompilerUse>
            <useIncrementalCompilation>false</useIncrementalCompilation>

        <compilerArgs>
            <arg>-Xep:ParameterName:OFF</arg>
        </compilerArgs>
        <compilerArguments>
            <endorseddirs>${endorsed.dir}</endorseddirs>
        </compilerArguments>
     </configuration>
     <dependencies>
        <dependency>
          <groupId>org.codehaus.plexus</groupId>
          <artifactId>plexus-compiler-javac-errorprone</artifactId>
          <version>2.8.5</version>
        </dependency>
        <dependency>
          <groupId>com.google.errorprone</groupId>
          <artifactId>error_prone_core</artifactId>
          <version>${google.error.prone.version}</version>
        </dependency>
      </dependencies>
  </plugin>

I get this error:

CompilerException: InvocationTargetException: invalid target release: 11

I tried following this information: Unable to compile simple Java 10 / Java 11 project with Maven

However, upgrading ASM did not change anything.

As per the maven documentation:

The Compiler Plugin is used to compile the sources of your project. Since 3.0, the default compiler is javax.tools.JavaCompiler (if you are using java 1.6) and is used to compile Java sources. If you want to force the plugin using javac, you must configure the plugin option forceJavacCompilerUse.

Also note that at present the default source setting is 1.6 and the default target setting is 1.6, independently of the JDK you run Maven with. You are highly encouraged to change these defaults by setting source and target as described in Setting the -source and -target of the Java Compiler.

After changing the source and target to 11 as follows:

<plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>11</source>
                    <target>11</target>
                </configuration>
            </plugin>

the above mentioned error of invalid java 11 version didn't appear

I put in properties this: <java.version>1.11</java.version> and in maven compiler pugin of this way: <source>11</source> <target>11</target>. It works for me.

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