user14647130
user14647130

Reputation:

Changing a 1.8 Maven Project to compile to 1.16 produces "invalid target release 1.16"

I've been searching a solution for hours, couldn't even find 1 post about maven compilation to 1.16

I recently decided to one of my projects from java 8 to 16, so I installed 16 JDK and changed my build section(in pom.xml) accordingly:

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.8.1</version>
            <configuration>
                <source>1.16</source> //used to be 1.8
                <target>1.16</target> //used to be 1.8
                <compilerArgs>
                    <arg>-parameters</arg>
                </compilerArgs>
            </configuration>
        </plugin>
    </plugins>
</build>

But I get the following error when I try to install:

[INFO] Total time:  0.628 s
[INFO] Finished at: 2021-08-03T22:40:27+03:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project employeme: Fatal error compiling: error: invalid target release: 1.16 -> [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

Upvotes: 1

Views: 1677

Answers (2)

queeg
queeg

Reputation: 9394

I ran into a similar issue despite the fact that my settings were

<source>16</source> //used to be 8
<target>16</target> //used to be 8

The real insight came up when I ran

mvn --version

as this one pointed out I was running a current maven with JDK 11.

The solution was to change JAVA_HOME to point to my JDK 16 installation before running maven.

Upvotes: 0

Gerold Broser
Gerold Broser

Reputation: 14762

  1. It's not 1.16, it's 16.
  2. You don't have to configure the maven-compiler-plugin.
  3. You can use the new release option.
  <properties>
    <maven.compiler.release>16</maven.compiler.release>
  </properties>

Upvotes: 1

Related Questions