Migrate to Java 17

MSAL

This 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.UpgradeToJava17
mod run . --recipe=org.openrewrite.java.migrate.UpgradeToJava17

Install 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.

  1. Enable Lombok annotation processor
  2. Migrate to Java 11
  3. Upgrade build to Java 17
  4. Change code to use Java 17's instanceof pattern matching
  5. Add @Serial annotation to serialVersionUID
  6. Remove Runtime.traceInstructions(boolean) and Runtime.traceMethodCalls methods
  7. Change javax.tools.ToolProvider methods calls to static
  8. Change java.lang.reflect.Modifier and java.lang.invoke.ConstantBootstraps method calls to static
  9. Add explicit import for Record classes
  10. Use text blocks
  11. Use java.security.cert instead of javax.security.cert
  12. Adopt setLongThreadID in java.util.logging.LogRecord
  13. Use SunJSSE instead of com.sun.net.ssl.internal.ssl.Provider
  14. Set visibility of premain and agentmain methods to public
  15. Remove Thread.countStackFrames() method
  16. Replace finalize method in java.util.zip.ZipFile, java.util.zip.Inflater and java.util.zip.Deflater
  17. Replace SSLSession.getPeerCertificateChain() method
  18. Replace com.sun.net.ssl package
  19. Replace RMIConnectorServer.CREDENTIAL_TYPES constant
  20. Replace finalize method in java.io.FileInputStream and java.io.FileOutputStream
  21. Upgrade plugins to Java 17 compatible versions
  22. Upgrade Gradle or Maven dependency versions com.google.inject:guice:5.x
  23. Upgrade Gradle or Maven dependency versions commons-codec:commons-codec:1.17.x
  24. Upgrade Maven dependency version com.github.spotbugs:spotbugs-maven-plugin:4.9.x
  25. Upgrade Maven plugin version com.github.spotbugs:spotbugs-maven-plugin:4.9.x
  26. Change Gradle or Maven dependency org.mapstruct:mapstruct-jdk8
  27. Upgrade Gradle or Maven dependency versions org.mapstruct:mapstruct*:1.6.x
  28. Add lombok-mapstruct-binding when both MapStruct and Lombok are used