3

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.

Walter
  • 1,290
  • 2
  • 21
  • 46
  • 6
    You're compiling on an older version of Java. Run `mvn -v` and maven will tell you which java version it's running on – ernest_k Sep 28 '19 at 15:36
  • Yes, I checked that earlier, it is still showing 11. Apache Maven 3.6.2 (40f52333136460af0dc0d7232c0dc0bcf0d9e117; 2019-08-27T11:06:16-04:00) Maven home: /opt/Apache/maven/3.6.2 Java version: 11.0.3-gentoo, vendor: Gentoo, runtime: /usr/lib64/openjdk-11 Default locale: en_US, platform encoding: UTF-8 OS name: "linux", version: "4.19.27-gentoo-r1", arch: "amd64", family: "unix" – Walter Sep 28 '19 at 15:36
  • Ah, I had manually "upgraded" to 11, I missed javac -> 11 – Walter Sep 28 '19 at 15:38
  • I am still having problems after fixing my javac symlink. My JAVA_HOME is pointing to 11. I will poke around some more ... – Walter Sep 28 '19 at 15:41
  • 3
    It should be enough to make JAVA_HOME point to your JDK11 installation directory. That's what maven uses by default. You can do that just in the shell session in which you'll run maven (and keep the other java version as system default if needed) – ernest_k Sep 28 '19 at 15:47
  • 1
    You should simply use JAVA_HOME nothing else no tricks with symlinks etc. that will fail. Furthermore I don't understand why you have added some many dependencies to the maven-compiler-plugin? Apart from that you should use supplemental `11` to use the `--release` switch of javac for checking bootclasspath etc. in JDK9+. I'm working on a JDK11 project which does not need such configuration. BTW: If I correctly remember the endorsed directory is not supported anymore (can't remember which versions)... – khmarbaise Sep 28 '19 at 18:55
  • I have the other dependencies there so that I can leverage google error prone to catch mistakes at compile time. – Walter Sep 29 '19 at 01:05
  • First I would suggest to keep the smallest configuration ...furthermore the defaults are working very well...What kind of mistakes will google catch which the compiler can't ? – khmarbaise Sep 29 '19 at 13:49
  • I removed the google error prone reference and that allowed me to move forward. I have other errors I'm working through now. – Walter Oct 02 '19 at 02:49

2 Answers2

0

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

yolob 21
  • 385
  • 4
  • 19
0

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.

Fernando Pie
  • 895
  • 1
  • 12
  • 28