Upgrading a Spring Boot project from JDK 8 to JDK 11

Viewed 6896

I'm trying to upgrading a Spring boot application from JDK 8 to JDK 11 and I made the following changes:

1.Use java.version in pom.xml

<properties>
<java.version>11</java.version>
</properties>

2.Add dependencies for modules removed:

<!--1.JAF(java.activation)-->

<dependency>
<groupId>com.sun.activation</groupId>
<artifactId>javax.activation</artifactId>
</dependency>

<!--2.JTA(java.transaction)-->
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
</dependency>

<!--3.JAXB(java.xml.bind)-->
<!--API-->
<dependency>
<groupId>jakarta.xml.bind</groupId>
<artifactId>jakarta.xml.bind-api</artifactId>
<version>2.3.2</version>
</dependency>

<!--Runtime-->
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-runtime</artifactId>
</dependency>

<!--4.JAX-WS(java.xml.ws)-->
<!--API-->
<dependency>
<groupId>jakarta.xml.ws</groupId>
<artifactId>jakarta.xml.ws-api</artifactId>
<version>2.3.2</version>
</dependency>

<!--Runtime-->
<dependency>
<groupId>com.sun.xml.ws</groupId>
<artifactId>jaxws-rt</artifactId>
<version>2.3.2</version>
</dependency>

<!--5.CommonsAnnotations(java.xml.ws.annotation)-->
<dependency>
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
</dependency>

3.Added the following plugins:

<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-surefire-plugin</artifactId>
<version>2.22.0</version>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.22.0</version>
</plugin>

When I run mvn clean package, I get an error:

compiler message file broken:key=compiler.misc.msg.bugarguments=11.0.4-redhat,{1},{2},{3},{4},{5},{6},{7}
java.lang.StackOverflowError
atjdk.compiler/com.sun.tools.javac.comp.Attr.attribTree(Attr.java:652)
atjdk.compiler/com.sun.tools.javac.comp.Attr.visitSelect(Attr.java:3573)
atjdk.compiler/com.sun.tools.javac.tree.JCTree$JCFieldAccess.accept(JCTree.java:2114)
atjdk.compiler/com.sun.tools.javac.comp.Attr.attribTree(Attr.java:655)
atjdk.compiler/com.sun.tools.javac.comp.Attr.visitApply(Attr.java:2006)
atjdk.compiler/com.sun.tools.javac.tree.JCTree$JCMethodInvocation.accept(JCTree.java:1634)

Any thoughts on what I'm doing wrong or anything else I need to do? Thanks in advance.

1 Answers

I updated my SpringBoot project from Java 8 version to Java 16 just by adding

<properties>
    <java.version>16</java.version>
</properties>

Of course first I installed Java 16 JDK on my Mac.

And also setting in InteliJ preferences to run Maven

JDK importer: JAVA_HOME(/Library/Java/JavaVirtualMachines/jdk-16.jdk/Contents/Home)

You can find it in IntelliJ IDEA if you go

Preferences > Building, Execution, Deployment > Building Tools > Maven > Importing

Spring Boot applications specify the JDK version inside the properties tags in the pom.xml file.

Your parent POM allows us to configure default plugins and multiple properties including the Java version — by default, the Java version is 1.8.

However, we can override the default version of the parent by specifying the java.version property:

<properties>
    <java.version>16</java.version>
</properties>

By setting the java.version property, we declare that the source and the target Java versions are both equal to 16.

Above steps work only for SpringBoot applications.

If there is need to update Spring application maybe these links help:

https://www.baeldung.com/maven-java-version

https://maven.apache.org/plugins/maven-compiler-plugin/examples/set-compiler-source-and-target.html

Related