Migrate to Java 11 | OpenRewrite Docs
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
Recipe source
GitHub: java-version-11.yml, Issue Tracker, Maven Central
info
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.
This recipe is available under the Moderne Source Available License.
Definition
- Recipe List
- Yaml Recipe List
- Migrate to Java 8
- Prefer
java.util.Base64instead ofsun.misc- useMimeCoder:
false
- useMimeCoder:
- Remove explicit casts on
Arrays.asList(..).toArray() - Add explicit JAXB API dependencies and runtime
- Add explicit JAX-WS dependencies
- Migrate JAXB-WS Plugin
- Add explicit Inject dependencies
- Add explicit Common Annotations dependencies
BigDecimalrounding constants toRoundingModeenums- Use primitive wrapper
valueOfmethod - Use try-with-resources
- Use modernized
java.util.concurrentAPIs - Use modernized
java.langAPIs - Remove method invocations
- methodPattern:
java.lang.Runtime runFinalizersOnExit(boolean)
- methodPattern:
- Remove method invocations
- methodPattern:
java.lang.System runFinalizersOnExit(boolean)
- methodPattern:
- Use modernized
java.util.loggingAPIs - Migrate Lombok to a Java 11 compatible version
- Use modernized
java.netAPIs - Replace
Paths.getwithPath.of - Use modernized
java.sqlAPIs - Use modernized
javax.lang.model.utilAPIs - Use modernized
javax.management.monitorAPIs - Use modernized
javax.xml.streamAPIs - 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.Policywithjava.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.AWTUtilitiesstatic 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
getLocalizedInputStreamandgetLocalizedOutputStreamwith direct assignment- localizedInputStreamMethodMatcher:
java.lang.Runtime getLocalizedInputStream(java.io.InputStream) - localizedOutputStreamMethodMatcher:
java.lang.Runtime getLocalizedOutputStream(java.io.OutputStream)
- localizedInputStreamMethodMatcher:
- Catch
TypeNotPresentExceptionthrown byClass.getAnnotation() - Replace
IllegalArgumentExceptionwithAlreadyConnectedExceptioninDatagramChannel.send()method - Return String
jkswhenKeyStore.getDefaultType()is called
Used by
This recipe is used as part of the following composite recipes:
Examples
Example 1
PathsGetToPathOfTest#convertPathsGetToPathOf
- java
- Diff
Before
import java.nio.file.Path;
import java.nio.file.Paths;
import java.net.URI;
class A {
Path pathA = Paths.get("path");
Path pathB = Paths.get("path", "subpath");
Path pathC = Paths.get(URI.create("file:///path"));
}
After
import java.nio.file.Path;
import java.net.URI;
class A {
Path pathA = Path.of("path");
Path pathB = Path.of("path", "subpath");
Path pathC = Path.of(URI.create("file:///path"));
}
Example 2
PathsGetToPathOfTest#convertPathsGetToPathOf
- java
- Diff
Before
import java.nio.file.Path;
import java.nio.file.Paths;
import java.net.URI;
class A {
Path pathA = Paths.get("path");
Path pathB = Paths.get("path", "subpath");
Path pathC = Paths.get(URI.create("file:///path"));
}
After
import java.nio.file.Path;
import java.net.URI;
class A {
Path pathA = Path.of("path");
Path pathB = Path.of("path", "subpath");
Path pathC = Path.of(URI.create("file:///path"));
}
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.gradlefile:build.gradle
plugins {
id("org.openrewrite.rewrite") version("latest.release")
}
rewrite {
activeRecipe("org.openrewrite.java.migrate.Java8toJava11")
setExportDatatables(true)
}
repositories {
mavenCentral()
}
dependencies {
rewrite("org.openrewrite.recipe:rewrite-migrate-java:3.31.1")
} - Run
gradle rewriteRunto run the recipe.
See how this recipe works across multiple open-source repositories

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
- SourcesFileResults
- SearchResults
- SourcesFileErrors
- RecipeRunStats
- MavenMetadataFailures
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. |