Migrate to Java 25
Upgrading to Java 25 unlocks new language features such as instance main methods and the simplified IO console class. It also retires APIs that have been deprecated for removal – most notably the SecurityManager along with several legacy I/O patterns. The changes themselves are mechanical, but applying them across thousands of files by hand is slow and easy to get wrong.
The UpgradeToJava25 recipe applies these changes automatically: it adopts the new APIs, replaces deprecated ones with their modern equivalents, and updates build files to target Java 25.
In this guide, we will show you how to run this recipe on the Moderne Platform or with the Moderne CLI.
Codebases on Java 8, 11, 17, or 21 are all valid starting points. UpgradeToJava25 includes the earlier upgrade recipes transitively, so you do not need to chain multiple migrations.
What this recipe does
UpgradeToJava25 is a composite recipe that bundles many smaller transformations. Some of the most visible changes this recipe makes to your code include:
- Migrate
public static void main(String[] args)to instancevoid main()– takes advantage of JEP 512 to drop thestaticmodifier and the unusedargsparameter from main methods. - Migrate
System.out.printto Java 25 IO utility class – swapsSystem.out.print(ln)calls for the newIO.print(ln)methods. - Use
Process#waitFor(Duration)– replaces the legacy(timeout, TimeUnit)overload with the type-safeDurationoverload. - Replace unused variables with underscore – uses the
_placeholder for unused lambda parameters and exception variables (JEP 456).
Beyond the source code, the recipe also updates Maven and Gradle build files to target Java 25 and bumps build plugins to Java 25-compatible versions. For the complete list of sub-recipes, see the recipe catalog page.
Example
Here is a small class before and after UpgradeToJava25 runs:
import java.util.concurrent.TimeUnit;
public class Greeter {
public static void main(String[] args) throws Exception {
Process p = new ProcessBuilder("echo", "hi").start();
p.waitFor(5, TimeUnit.SECONDS);
System.out.println("done");
}
}
import java.io.IO;
import java.time.Duration;
public class Greeter {
void main() throws Exception {
Process p = new ProcessBuilder("echo", "hi").start();
p.waitFor(Duration.ofSeconds(5));
IO.println("done");
}
}
Running the recipe
- Moderne Platform
- Moderne CLI
- Sign in to your Moderne tenant or app.moderne.io.
- (Optionally) Use the Organization selector to scope the run to the repositories you want to upgrade.
- Search for the
Migrate to Java 25recipe (Moderne Platform link). - Click Dry run.
For a step-by-step walkthrough of the Moderne Platform UI, see Quickstart: Using the Moderne Platform.
Make sure you have built or downloaded Lossless Semantic Trees (LSTs) for the repositories you want to upgrade.
This recipe has no required configuration options. Users of Moderne can run it via the Moderne CLI.
You will need to have configured the Moderne CLI on your machine before you can run the following command.
mod run . --recipe UpgradeToJava25
If the recipe is not available locally, then you can install it using:
mod config recipes jar install org.openrewrite.recipe:rewrite-migrate-java:3.34.0
Reviewing and committing the changes
Running the recipe never modifies your source repositories directly. Instead, the changes are presented as a diff that you can inspect before deciding what to commit. Review them with whatever workflow fits your team, then use the Moderne Platform's commit options or the mod git CLI commands to push the changes across the affected repositories.
Additional reading
- Tracking migrations – use data tables and visualizations to track the rollout of a Java 25 upgrade across many repositories.