Home > Software engineering >  Update Maven Project to Java 17 in Eclipse 2022-03 is not working
Update Maven Project to Java 17 in Eclipse 2022-03 is not working

Time:03-25

I have a pristine Eclipse 2022-03 with JRE's 1.8 & 17 defined under Windows 10.

Having created a new Maven Project I tried Maven/Update Project... but it has no effect: the JDK remains 1.8.

My pom.xml looks like this:

<project
        xmlns="http://maven.apache.org/POM/4.0.0"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">

    <modelVersion>4.0.0</modelVersion>
    <groupId>de.domain</groupId>
    <artifactId>jdk17.project</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>JDK 17 Project</name>

    <properties>
        <maven.compiler.source>17</maven.compiler.source>
        <maven.compiler.target>17</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>
</project>

I then changed it to:

<project
        xmlns="http://maven.apache.org/POM/4.0.0"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">

    <modelVersion>4.0.0</modelVersion>
    <groupId>de.domain</groupId>
    <artifactId>jdk17.project</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>JDK 17 Project</name>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

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

This worked, the JDK was updated to 17. However, I find it rather long-winded.

Anyone know why the other pom is not working?

Addendum: the following 2 JRE's are configuered

  • 1.8 Oracle unlimited Crypto
  • 17 openJDK (Zulu Release with JavaFX bundled)

JRE's

Addendum: Maven settings.xml

<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
                      http://maven.apache.org/xsd/settings-1.0.0.xsd">
  <localRepository/>
  <interactiveMode/>
  <usePluginRegistry/>
  <offline/>
  <pluginGroups/>
  <servers/>
  <mirrors/>
  <profiles>
    <profile>
        <id>java8</id>
        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>
        <properties>
            <maven.compiler.source>1.8</maven.compiler.source>
            <maven.compiler.target>1.8</maven.compiler.target>
        </properties>
    </profile>
  </profiles>
  <activeProfiles/>
</settings>

Addendum: Project/Java Compiler

Project/Java Compiler

CodePudding user response:

This is caused by your Maven .m2/settings.xml file which overrides the properties of your pom.xml file.

Maven on the command line also behaves this way (you can test this e.g. with a record: with your settings.xml file the build fails and without your settings.xml file the build will be successful).

Rather set the Java version in each parent pom.xml file than the (default) Java version in your Maven .m2/settings.xml file this way.

  • Related