Migrate to Java 11
org.openrewrite.java.migrate.Java8toJava11
This recipe will apply changes commonly needed when upgrading to Java 11. 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 11 as the target/source and plugins will be also be upgraded to versions that are compatible with Java 11.
Tags
- jaxb
- deprecated
- java11
- jaxws
- jakarta
Recipe source
GitHub, Issue Tracker, Maven Central
This recipe is composed of more than one recipe. If you want to customize the set of recipes this is composed of, you can find and copy the GitHub source for the recipe from the link above.
License
This recipe is available under the Moderne Source Available License.
Definition
- Recipe List
- Yaml Recipe List
- Migrate to Java 8
- Prefer
java.util.Base64
instead ofsun.misc
- useMimeCoder:
false
- useMimeCoder:
- Remove explicit casts on
Arrays.asList(..).toArray()
- Add explicit JAXB dependencies
- Add explicit JAX-WS dependencies
- Add explicit Inject dependencies
- Add explicit Common Annotations dependencies
BigDecimal
rounding constants toRoundingMode
enums- Use primitive wrapper
valueOf
method - Use modernized
java.util.concurrent
APIs - Use modernized
java.lang
APIs - Remove method invocations
- methodPattern:
java.lang.Runtime runFinalizersOnExit(boolean)
- methodPattern:
- Remove method invocations
- methodPattern:
java.lang.System runFinalizersOnExit(boolean)
- methodPattern:
- Use modernized
java.util.logging
APIs - Migrate Lombok to a Java 11 compatible version
- Use modernized
java.net
APIs - Replace
Paths.get
withPath.of
- Use modernized
java.sql
APIs - Use modernized
javax.lang.model.util
APIs - Use modernized
javax.management.monitor
APIs - Use modernized
javax.xml.stream
APIs - Remove Cobertura Maven plugin
- Upgrade build to Java 11
- Prefer
Optional.isEmpty()
- Prefer
Optional.isPresent()
Stream<Optional>
idiom recipe- Use
com.sun.xml.bind.*
instead ofcom.sun.xml.internal.bind.*
- Replace deprecated methods in
SecurityManager
- Upgrade plugins to Java 11 compatible versions
- Replace
javax.security.auth.Policy
withjava.security.Policy
- Replace
java.lang.ref.Reference.clone()
with constructor call - Remove
Thread.destroy()
andThread.stop(Throwable)
- Replace AWT
getPeer()
method- getPeerMethodPattern:
java.awt.* getPeer()
- lightweightPeerFQCN:
java.awt.peer.LightweightPeer
- getPeerMethodPattern:
- Migrate to Scala 2.12.+
- Replace
com.sun.awt.AWTUtilities
static method invocations- getAWTIsWindowsTranslucencyPattern:
com.sun.awt.AWTUtilities isTranslucencySupported(com.sun.awt.AWTUtilities.Translucency)
- isWindowOpaquePattern:
com.sun.awt.AWTUtilities isWindowOpaque(java.awt.Window)
- isTranslucencyCapablePattern:
com.sun.awt.AWTUtilities isTranslucencyCapable(java.awt.GraphicsConfiguration)
- setWindowOpacityPattern:
com.sun.awt.AWTUtilities setWindowOpacity(java.awt.Window, float)
- getWindowOpacityPattern:
com.sun.awt.AWTUtilities getWindowOpacity(java.awt.Window)
- getWindowShapePattern:
com.sun.awt.AWTUtilities getWindowShape(java.awt.Window)
- setComponentMixingCutoutShapePattern:
com.sun.awt.AWTUtilities setComponentMixingCutoutShape(java.awt.Component,java.awt.Shape)
- getAWTIsWindowsTranslucencyPattern:
- Replace
getLocalizedInputStream
andgetLocalizedOutputStream
with direct assignment- localizedInputStreamMethodMatcher:
java.lang.Runtime getLocalizedInputStream(java.io.InputStream)
- localizedOutputStreamMethodMatcher:
java.lang.Runtime getLocalizedOutputStream(java.io.OutputStream)
- localizedInputStreamMethodMatcher:
- Catch
TypeNotPresentException
thrown byClass.getAnnotation()
- Replace
IllegalArgumentException
withAlreadyConnectedException
inDatagramChannel.send()
method
---
type: specs.openrewrite.org/v1beta/recipe
name: org.openrewrite.java.migrate.Java8toJava11
displayName: Migrate to Java 11
description: This recipe will apply changes commonly needed when upgrading to Java 11. 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 11 as the target/source and plugins will be also be upgraded to versions that are compatible with Java 11.
tags:
- jaxb
- deprecated
- java11
- jaxws
- jakarta
recipeList:
- org.openrewrite.java.migrate.UpgradeToJava8
- org.openrewrite.java.migrate.UseJavaUtilBase64:
useMimeCoder: false
- org.openrewrite.java.migrate.CastArraysAsListToList
- org.openrewrite.java.migrate.javax.AddJaxbDependencies
- org.openrewrite.java.migrate.javax.AddJaxwsDependencies
- org.openrewrite.java.migrate.javax.AddInjectDependencies
- org.openrewrite.java.migrate.javax.AddCommonAnnotationsDependencies
- org.openrewrite.staticanalysis.BigDecimalRoundingConstantsToEnums
- org.openrewrite.staticanalysis.PrimitiveWrapperClassConstructorToValueOf
- org.openrewrite.java.migrate.concurrent.JavaConcurrentAPIs
- org.openrewrite.java.migrate.lang.JavaLangAPIs
- org.openrewrite.java.RemoveMethodInvocations:
methodPattern: java.lang.Runtime runFinalizersOnExit(boolean)
- org.openrewrite.java.RemoveMethodInvocations:
methodPattern: java.lang.System runFinalizersOnExit(boolean)
- org.openrewrite.java.migrate.logging.JavaLoggingAPIs
- org.openrewrite.java.migrate.lombok.UpdateLombokToJava11
- org.openrewrite.java.migrate.net.JavaNetAPIs
- org.openrewrite.java.migrate.nio.file.PathsGetToPathOf
- org.openrewrite.java.migrate.sql.JavaSqlAPIs
- org.openrewrite.java.migrate.javax.JavaxLangModelUtil
- org.openrewrite.java.migrate.javax.JavaxManagementMonitorAPIs
- org.openrewrite.java.migrate.javax.JavaxXmlStreamAPIs
- org.openrewrite.java.migrate.cobertura.RemoveCoberturaMavenPlugin
- org.openrewrite.java.migrate.UpgradeBuildToJava11
- org.openrewrite.java.migrate.util.OptionalNotPresentToIsEmpty
- org.openrewrite.java.migrate.util.OptionalNotEmptyToIsPresent
- org.openrewrite.java.migrate.util.OptionalStreamRecipe
- org.openrewrite.java.migrate.InternalBindPackages
- org.openrewrite.java.migrate.RemovedSecurityManagerMethods
- org.openrewrite.java.migrate.UpgradePluginsForJava11
- org.openrewrite.java.migrate.RemovedPolicy
- org.openrewrite.java.migrate.ReferenceCloneMethod
- org.openrewrite.java.migrate.ThreadStopDestroy
- org.openrewrite.java.migrate.ReplaceAWTGetPeerMethod:
getPeerMethodPattern: java.awt.* getPeer()
lightweightPeerFQCN: java.awt.peer.LightweightPeer
- org.openrewrite.scala.migrate.UpgradeScala_2_12
- org.openrewrite.java.migrate.ReplaceComSunAWTUtilitiesMethods:
getAWTIsWindowsTranslucencyPattern: com.sun.awt.AWTUtilities isTranslucencySupported(com.sun.awt.AWTUtilities.Translucency)
isWindowOpaquePattern: com.sun.awt.AWTUtilities isWindowOpaque(java.awt.Window)
isTranslucencyCapablePattern: com.sun.awt.AWTUtilities isTranslucencyCapable(java.awt.GraphicsConfiguration)
setWindowOpacityPattern: com.sun.awt.AWTUtilities setWindowOpacity(java.awt.Window, float)
getWindowOpacityPattern: com.sun.awt.AWTUtilities getWindowOpacity(java.awt.Window)
getWindowShapePattern: com.sun.awt.AWTUtilities getWindowShape(java.awt.Window)
setComponentMixingCutoutShapePattern: com.sun.awt.AWTUtilities setComponentMixingCutoutShape(java.awt.Component,java.awt.Shape)
- org.openrewrite.java.migrate.ReplaceLocalizedStreamMethods:
localizedInputStreamMethodMatcher: java.lang.Runtime getLocalizedInputStream(java.io.InputStream)
localizedOutputStreamMethodMatcher: java.lang.Runtime getLocalizedOutputStream(java.io.OutputStream)
- org.openrewrite.java.migrate.ArrayStoreExceptionToTypeNotPresentException
- org.openrewrite.java.migrate.IllegalArgumentExceptionToAlreadyConnectedException
Usage
This recipe has no required configuration options. It can be activated by adding a dependency on org.openrewrite.recipe:rewrite-migrate-java
in your build file or by running a shell command (in which case no build changes are needed):
- Gradle
- Gradle init script
- Maven POM
- Maven Command Line
- Moderne CLI
- Add the following to your
build.gradle
file:
plugins {
id("org.openrewrite.rewrite") version("6.29.0")
}
rewrite {
activeRecipe("org.openrewrite.java.migrate.Java8toJava11")
setExportDatatables(true)
}
repositories {
mavenCentral()
}
dependencies {
rewrite("org.openrewrite.recipe:rewrite-migrate-java:2.31.0")
}
- Run
gradle rewriteRun
to run the recipe.
- Create a file named
init.gradle
in the root of your project.
initscript {
repositories {
maven { url "https://plugins.gradle.org/m2" }
}
dependencies { classpath("org.openrewrite:plugin:6.29.0") }
}
rootProject {
plugins.apply(org.openrewrite.gradle.RewritePlugin)
dependencies {
rewrite("org.openrewrite.recipe:rewrite-migrate-java:2.31.0")
}
rewrite {
activeRecipe("org.openrewrite.java.migrate.Java8toJava11")
setExportDatatables(true)
}
afterEvaluate {
if (repositories.isEmpty()) {
repositories {
mavenCentral()
}
}
}
}
- Run the recipe.
gradle --init-script init.gradle rewriteRun
- Add the following to your
pom.xml
file:
<project>
<build>
<plugins>
<plugin>
<groupId>org.openrewrite.maven</groupId>
<artifactId>rewrite-maven-plugin</artifactId>
<version>5.47.0</version>
<configuration>
<exportDatatables>true</exportDatatables>
<activeRecipes>
<recipe>org.openrewrite.java.migrate.Java8toJava11</recipe>
</activeRecipes>
</configuration>
<dependencies>
<dependency>
<groupId>org.openrewrite.recipe</groupId>
<artifactId>rewrite-migrate-java</artifactId>
<version>2.31.0</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</project>
- Run
mvn rewrite:run
to run the recipe.
You will need to have Maven installed on your machine before you can run the following command.
mvn -U org.openrewrite.maven:rewrite-maven-plugin:run -Drewrite.recipeArtifactCoordinates=org.openrewrite.recipe:rewrite-migrate-java:RELEASE -Drewrite.activeRecipes=org.openrewrite.java.migrate.Java8toJava11 -Drewrite.exportDatatables=true
You will need to have configured the Moderne CLI on your machine before you can run the following command.
mod run . --recipe Java8toJava11
If the recipe is not available locally, then you can install it using:
mod config recipes jar install org.openrewrite.recipe:rewrite-migrate-java:2.31.0
See how this recipe works across multiple open-source repositories
Run this recipe on OSS repos at scale with the Moderne SaaS.
The community edition of the Moderne platform enables you to easily run recipes across thousands of open-source repositories.
Please contact Moderne for more information about safely running the recipes on your own codebase in a private SaaS.
Data Tables
Source files that had results
org.openrewrite.table.SourcesFileResults
Source files that were modified by the recipe run.
Column Name | Description |
---|---|
Source path before the run | The source path of the file before the run. null when a source file was created during the run. |
Source path after the run | A recipe may modify the source path. This is the path after the run. null when a source file was deleted during the run. |
Parent of the recipe that made changes | In a hierarchical recipe, the parent of the recipe that made a change. Empty if this is the root of a hierarchy or if the recipe is not hierarchical at all. |
Recipe that made changes | The specific recipe that made a change. |
Estimated time saving | An estimated effort that a developer to fix manually instead of using this recipe, in unit of seconds. |
Cycle | The recipe cycle in which the change was made. |
Source files that errored on a recipe
org.openrewrite.table.SourcesFileErrors
The details of all errors produced by a recipe run.
Column Name | Description |
---|---|
Source path | The file that failed to parse. |
Recipe that made changes | The specific recipe that made a change. |
Stack trace | The stack trace of the failure. |
Recipe performance
org.openrewrite.table.RecipeRunStats
Statistics used in analyzing the performance of recipes.
Column Name | Description |
---|---|
The recipe | The recipe whose stats are being measured both individually and cumulatively. |
Source file count | The number of source files the recipe ran over. |
Source file changed count | The number of source files which were changed in the recipe run. Includes files created, deleted, and edited. |
Cumulative scanning time | The total time spent across the scanning phase of this recipe. |
99th percentile scanning time | 99 out of 100 scans completed in this amount of time. |
Max scanning time | The max time scanning any one source file. |
Cumulative edit time | The total time spent across the editing phase of this recipe. |
99th percentile edit time | 99 out of 100 edits completed in this amount of time. |
Max edit time | The max time editing any one source file. |
Contributors
Chuka Obinabo, Anu Ramamoorthy, BhavanaPidapa, Sam Snyder, traceyyoshima, Tim te Beek, Knut Wannheden, Jonathan Schnéider, Tyler Van Gorder, Yifeng Jin, Jonathan Schneider, Adam Slaski, Aaron Gershman, Daryl Robbins, Patrick, Aaron Gershman, Tim te Beek, Tim te Beek, Michael Keppler, Laurens Westerlaken, Shannon Pamperl, Josh Soref, Kun Li