maven with JDK11: javac: invalid flag: --release

Hengrui Jiang :

I'm trying to set up a simple maven project with java 11. As I want to keep JAVA_HOME to be version 8, I'm using maven-toolchains-plugin to make maven use jdk11 for this project.

While maven successfully finds a matching toolchain for jdk-11.0.1, I keep getting " javac: invalid flag: --release". What am I doing wrong?

Here are the plugin configurations:

 <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.8.0</version>
    <configuration>
      <release>11</release>
    </configuration>
  </plugin>
  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-toolchains-plugin</artifactId>
    <version>1.1</version>
    <executions>
      <execution>
        <goals>
          <goal>toolchain</goal>
        </goals>
      </execution>
    </executions>
    <configuration>
      <toolchains>
        <jdk>
          <version>11</version>
        </jdk>
      </toolchains>
    </configuration>
  </plugin>

The toolchain is defined as:

 <toolchain>
   <type>jdk</type>
   <provides>
     <version>11</version>
     <id>JavaSE-1.11</id>
   </provides>
   <configuration>
     <jdkHome>C:\Program Files\Java\jdk-11.0.1\bin</jdkHome>
   </configuration>
<toolchain>
Hengrui Jiang :

As I found out, the configuration is just fine. The problem was that jdkHome in toolchains.xml was pointing to the \jdk-11.0.1\bin direction instead of \jdk-11.0.1 directly..... Using <jdkHome>C:\Program Files\Java\jdk-11.0.1</jdkHome> solves the problem..

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=69803&siteId=1