Skip to main content

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.

info

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:

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:

Before
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");
}
}
After
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

  1. Sign in to your Moderne tenant or app.moderne.io.
  2. (Optionally) Use the Organization selector to scope the run to the repositories you want to upgrade.
  3. Search for the Migrate to Java 25 recipe (Moderne Platform link).
  4. Click Dry run.

For a step-by-step walkthrough of the Moderne Platform UI, see Quickstart: Using the Moderne Platform.

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.