Migrate to Java 17
MSALThis recipe will apply changes commonly needed when migrating to Java 17. Specifically, for those applications that are built on Java 8, this recipe will update and add dependencies on J2EE libraries that are no longer directly bundled with the JDK. This recipe will also replace deprecated API with equivalents when there is a clear migration strategy. Build files will also be updated to use Java 17 as the target/source and plugins will also be upgraded to versions that are compatible with Java 17.
org. openrewrite. java. migrate. UpgradeToJava17mod run . --recipe= org. openrewrite. java. migrate. UpgradeToJava17Install it once from Recipe actions, then run it on every repository under the current directory. New to the Moderne CLI? Set it up.
Recipe list
It runs these recipes, in this order.
- Enable Lombok annotation processor
- Migrate to Java 11
- Upgrade build to Java 17
- Change code to use Java 17's
instanceofpattern matching - Add
@Serialannotation toserialVersionUID - Remove
Runtime.traceInstructions(boolean)andRuntime.traceMethodCallsmethods - Change
javax.tools.ToolProvidermethods calls to static - Change
java.lang.reflect.Modifierandjava.lang.invoke.ConstantBootstrapsmethod calls to static - Add explicit import for
Recordclasses - Use text blocks
- Use
java.security.certinstead ofjavax.security.cert - Adopt
setLongThreadIDinjava.util.logging.LogRecord - Use
SunJSSEinstead ofcom.sun.net.ssl.internal.ssl.Provider - Set visibility of
premainandagentmainmethods topublic - Remove
Thread.countStackFrames()method - Replace
finalizemethod injava.util.zip.ZipFile,java.util.zip.Inflaterandjava.util.zip.Deflater - Replace
SSLSession.getPeerCertificateChain()method - Replace
com.sun.net.sslpackage - Replace
RMIConnectorServer.CREDENTIAL_TYPESconstant - Replace
finalizemethod injava.io.FileInputStreamandjava.io.FileOutputStream - Upgrade plugins to Java 17 compatible versions
- Upgrade Gradle or Maven dependency versions
com.google.inject:guice:5.x - Upgrade Gradle or Maven dependency versions
commons-codec:commons-codec:1.17.x - Upgrade Maven dependency version
com.github.spotbugs:spotbugs-maven-plugin:4.9.x - Upgrade Maven plugin version
com.github.spotbugs:spotbugs-maven-plugin:4.9.x - Change Gradle or Maven dependency
org.mapstruct:mapstruct-jdk8 - Upgrade Gradle or Maven dependency versions
org.mapstruct:mapstruct*:1.6.x - Add
lombok-mapstruct-bindingwhen both MapStruct and Lombok are used