Generated banner for Java Upgrade
Generated logo for Java Upgrade

Java Upgrade

GitHubOfficialFirst committed by jduboisDistributed by GitHub

  • Skill
  • Guidelines
  • Software development
  • MIT
  • Low risk

From the author

Upgrade a Java project to a newer JDK (11 to 17, 17 to 21, 21 to 25) and adopt the new language and library features. Detects the current Java version from the build files, then loads only the matching per-version guide. Use when the user asks to upgrade Java, modernize Java code, or adopt records, sealed classes, pattern matching, virtual threads or other new Java features. For automated end-to-end upgrades see the modernize-java plugin.
— the description by jdubois

AutoGineer summary

Written by AutoGineer from the skill’s own files, not by the author

This skill provides a structured approach to upgrading Java applications across LTS versions (11 to 17, 17 to 21, 21 to 25). It helps developers assess their current environment, update build configurations, and incrementally adopt modern Java features like records, sealed classes, pattern matching, and virtual threads. The skill emphasizes safety by recommending small, reviewable changes and provides specific migration patterns for each version transition.

What it does

  • Detects current Java versions from build files like pom.xml and build.gradle.
  • Provides version-specific upgrade guides for LTS transitions.
  • Offers code migration patterns for modern Java features.
  • Advises on updating build configurations and dependencies.
  • Integrates with external tools like OpenRewrite for automated refactoring.
  • Provides guidance on handling namespace migrations such as javax to jakarta.

When to use it

  • When you need to upgrade a Java project to a newer JDK version.
  • When you want to modernize existing Java code with newer language features.
  • When you are unsure of the specific migration steps between two Java LTS versions.
  • When you need to adopt features like records, sealed classes, or virtual threads.

Advantages

  • Provides a clear, step-by-step path for complex version upgrades.
  • Focuses on safe, incremental refactoring to minimize breaking changes.
  • Includes specific code examples for modern Java syntax.
  • Helps identify necessary build tool and dependency updates.
  • Directs users to official documentation and migration resources.

Usage examples

“How do I upgrade my Java 11 project to Java 17?”
The agent will analyze your build files, outline the steps for the 11 to 17 transition, and provide specific migration patterns for features like records and sealed classes.
“Show me how to use virtual threads in my Java 21 project.”
The agent will explain the transition from platform threads to virtual threads using Executors.newVirtualThreadPerTaskExecutor and provide a code example.
“How can I use pattern matching for switch in Java 21?”
The agent will provide a comparison between traditional switch statements and the new pattern matching syntax, including examples with guarded patterns.

Install

  1. Download the skill as a ZIP:

    https://mp-staging.autogineer.com/agent-skills/github/java-upgrade/download
  2. Unzip it into the cross-client skills folder of your project:

    mkdir -p .agents/skills && unzip java-upgrade.zip -d .agents/skills

Documentation by jdubois

Java Upgrade

Help upgrade a Java project step by step and adopt new language features safely.

Need a more powerful, automated upgrade?

The Microsoft plugin modernize-java ("GitHub Copilot modernization - Java Upgrade CLI Plugin", also listed in this repository's plugins/external.json) upgrades Java applications from the command line. It can:

  • analyze the project, assess dependencies and generate a customizable upgrade plan you can review and edit;

  • execute the plan to automatically transform the codebase;

  • fix build issues and resolve migration errors during the upgrade, running test validations;

  • validate the application against known CVEs after the upgrade;

  • output a detailed summary (file changes, updated dependencies, test results, remaining issues) suitable for PRs or CI logs.

This skill provides lightweight, step-by-step guidance and works without the plugin; the plugin is the more powerful option for large or multi-step upgrades. It is a separate Microsoft plugin, not part of this repository's skills. To try it (see the plugin README for the recommended model):

npm install -g @github/copilot
copilot plugin marketplace add microsoft/modernize-java
copilot plugin install modernize-java@modernize-java
copilot --agent modernize-java:modernize-java

Workflow

  1. Detect the current and target versions. Read pom.xml (maven.compiler.release, java.version, toolchains), build.gradle* (java.toolchain, sourceCompatibility) and CI files. Never assume a target: ask the user if it is not stated.

  2. Upgrade one LTS at a time (11 → 17 → 21 → 25). Build and run the tests after each step.

  3. Load only the guide you need from the table below. Do not load all of them.

  4. Update the build first (compiler release, plugins, dependencies that need newer versions), then adopt language features incrementally in small, reviewable changes.

  5. Verify: ./mvnw verify or ./gradlew build, and fix deprecation and removal warnings before adopting new features.

  6. Automate and check upstream. Use OpenRewrite when available (for example org.openrewrite.java.migrate.UpgradeToJava21) and always fetch the version-specific official guide before editing; review the generated diff.

Upstream sources (read before upgrading)

Fetch the page for the target version; prefer it over this skill when they conflict. Full list with build-tool and agent compatibility pages: references/upstream-sources.md.

Per-version guides

UpgradeGuide
Java 11 → 17references/java-11-to-17.md
Java 17 → 21references/java-17-to-21.md
Java 21 → 25references/java-21-to-25.md

Rules

  • Prefer behavior-preserving refactorings; do not change public APIs unless asked.

  • Detect the project's frameworks (Spring Boot, Quarkus, Jakarta EE) and check their minimum supported Java version before raising the target.

  • Do not adopt preview features unless the user opts in and the build enables them explicitly.

  • For javax.* to jakarta.* namespace changes, use the javax-to-jakarta-migration skill if it is installed (gh skills install github/awesome-copilot javax-to-jakarta-migration); otherwise do the migration inline: update imports, META-INF service files and XML descriptors, and bump dependencies to Jakarta EE 9+ equivalents.

  • If the modernize-java plugin is installed and the user wants an automated upgrade, defer to it and use this skill for the per-version guides and the javax to jakarta safeguards.

Files

references/java-21-to-25.md

Java 21 to Java 25 Upgrade Guide

These instructions help GitHub Copilot assist developers in upgrading Java projects from JDK 21 to JDK 25, focusing on new language features, API changes, and best practices.

Language Features and API Changes in JDK 22-25

Pattern Matching Enhancements (JEP 455/488/507 - Preview in 23-25, still preview in 25)

Primitive Types in Patterns, instanceof, and switch

When working with pattern matching:

  • Suggest using primitive type patterns in switch expressions and instanceof checks

  • Example upgrade from traditional switch:

// Old approach (Java 21)
String s = switch (x.getStatus()) {
    case 0 -> "okay";
    case 1 -> "warning";
    case 2 -> "error";
    default -> "unknown status: " + x.getStatus();
};

// New approach (Java 25 Preview)
String s = switch (x.getStatus()) {
    case 0 -> "okay";
    case 1 -> "warning";
    case 2 -> "error";
    case int i -> "unknown status: " + i;
};
  • Enable preview features with --enable-preview flag

  • Suggest guard patterns for more complex conditions:

switch (x.getYearlyFlights()) {
    case 0 -> noCard();
    case int i when i >= 100 -> issueGoldCard();
    case int i -> issueBasicCard(i); // handle 1-99 range
}
Class-File API (JEP 466/484 - Second Preview in 23, Standard in 24)

Replacing ASM with Standard API

When detecting bytecode manipulation or class file processing:

  • Suggest migrating from ASM library to the standard Class-File API

  • Use java.lang.classfile package instead of org.objectweb.asm

  • Example migration pattern:

// Old ASM approach
ClassReader reader = new ClassReader(classBytes);
ClassWriter writer = new ClassWriter(reader, 0);
// ... ASM manipulation

// New Class-File API approach
ClassModel classModel = ClassFile.of().parse(classBytes);
byte[] newBytes = ClassFile.of().transformClass(classModel,
    ClassTransform.transformingMethods(methodTransform));
Markdown Documentation Comments (JEP 467 - Standard in 23)

JavaDoc Modernization

When working with JavaDoc comments:

  • Suggest converting HTML-heavy JavaDoc to Markdown syntax

  • Use /// for Markdown documentation comments

  • Example conversion:

// Old HTML JavaDoc
/**
 * Returns the <b>absolute</b> value of an {@code int} value.
 * <p>
 * If the argument is not negative, return the argument.
 * If the argument is negative, return the negation of the argument.
 * 
 * @param a the argument whose absolute value is to be determined
 * @return the absolute value of the argument
 */

// New Markdown JavaDoc  
/// Returns the **absolute** value of an `int` value.
///
/// If the argument is not negative, return the argument.
/// If the argument is negative, return the negation of the argument.
/// 
/// @param a the argument whose absolute value is to be determined
/// @return the absolute value of the argument
Derived Record Creation (JEP 468 - Not delivered)

Record Enhancement

JEP 468 (with expressions for records) did not ship in JDK 22-25 and is not available, even with --enable-preview.

  • Keep using explicit withX copy methods (or a copy-constructor style) until the feature is delivered

  • Example pattern:

public record Person(String name, int age, String email) {
    public Person withAge(int newAge) {
        return new Person(name, newAge, email);
    }
}

Person updated = person.withAge(30);
Stream Gatherers (JEP 473/485 - Second Preview in 23, Standard in 24)

Enhanced Stream Processing

When working with complex stream operations:

  • Suggest using Stream.gather() for custom intermediate operations

  • Import java.util.stream.Gatherers for built-in gatherers

  • Example usage:

// Custom windowing operations
List<List<String>> windows = stream
    .gather(Gatherers.windowSliding(3))
    .toList();

// Running sum: fold takes an initial-value supplier and emits a single result
Optional<Integer> total = numbers.stream()
    .gather(Gatherers.fold(() -> 0, (sum, element) -> sum + element))
    .findFirst();

// Running totals for every element
List<Integer> running = numbers.stream()
    .gather(Gatherers.scan(() -> 0, (sum, element) -> sum + element))
    .toList();

Migration Warnings and Deprecations

sun.misc.Unsafe Memory Access Methods (JEP 471 - Deprecated in 23)

When detecting sun.misc.Unsafe usage:

  • Warn about deprecated memory-access methods

  • Suggest migration to standard alternatives:

// Deprecated: sun.misc.Unsafe memory access
Unsafe unsafe = Unsafe.getUnsafe();
unsafe.getInt(object, offset);

// Preferred: VarHandle API
VarHandle vh = MethodHandles.lookup()
    .findVarHandle(MyClass.class, "fieldName", int.class);
int value = (int) vh.get(object);

// Or for off-heap: Foreign Function & Memory API
MemorySegment segment = MemorySegment.ofArray(new int[10]);
int value = segment.get(ValueLayout.JAVA_INT, offset);
JNI Usage Warnings (JEP 472 - Warnings in 24)

When detecting JNI usage:

  • Warn about upcoming restrictions on JNI usage

  • Suggest adding --enable-native-access flag for applications using JNI

  • Recommend migration to Foreign Function & Memory API where possible

  • Grant native access explicitly: --enable-native-access=ALL-UNNAMED (classpath) or --enable-native-access=com.example.app (module), or Enable-Native-Access: ALL-UNNAMED in an executable JAR manifest

Garbage Collection Updates

ZGC Generational Mode (JEP 474 - Default in 23, JEP 490 - Non-generational removed in 24)

When configuring garbage collection:

  • ZGC uses generational mode by default since JDK 23, and non-generational mode was removed in JDK 24

  • Remove -XX:-ZGenerational from JVM flags (and -XX:+ZGenerational, which is now redundant):

# Generational mode is the only mode in JDK 24+ (non-generational ZGC was removed)
-XX:+UseZGC

# -XX:-ZGenerational / -XX:+ZGenerational are obsolete; remove them from launch scripts
G1 Improvements (JEP 475 - Implemented in 24)

When using G1GC:

  • No code changes required - internal JVM optimization

  • May see improved compilation performance with C2 compiler

Vector API (JEP 469/508 - Still incubating in 25)

When working with numerical computations:

  • Suggest Vector API for SIMD operations (still incubating)

  • Add --add-modules jdk.incubator.vector

  • Example usage:

import jdk.incubator.vector.*;

// Traditional scalar computation
for (int i = 0; i < a.length; i++) {
    c[i] = a[i] + b[i];
}

// Vectorized computation
var species = IntVector.SPECIES_PREFERRED;
int i = 0;
for (; i < species.loopBound(a.length); i += species.length()) {
    var va = IntVector.fromArray(species, a, i);
    var vb = IntVector.fromArray(species, b, i);
    va.add(vb).intoArray(c, i);
}
for (; i < a.length; i++) { // scalar tail
    c[i] = a[i] + b[i];
}

Compilation and Build Configuration

Preview Features

For projects using preview features:

  • Add --enable-preview to compiler arguments

  • Add --enable-preview to runtime arguments

  • Maven configuration:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <configuration>
        <release>25</release>
        <compilerArgs>
            <arg>--enable-preview</arg>
        </compilerArgs>
    </configuration>
</plugin>

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <configuration>
        <argLine>--enable-preview</argLine>
    </configuration>
</plugin>
  • Gradle configuration:

java {
    toolchain {
        languageVersion = JavaLanguageVersion.of(25)
    }
}

tasks.withType<JavaCompile> {
    options.compilerArgs.add("--enable-preview")
}

tasks.withType<Test> {
    jvmArgs("--enable-preview")
}

Migration Strategy

Step-by-Step Upgrade Process
  1. Update Build Tools: Ensure Maven/Gradle supports JDK 25

  2. Update Dependencies: Check for JDK 25 compatibility

  3. Handle Warnings: Address deprecation warnings from JEPs 471/472

  4. Enable Preview Features: If using pattern matching or other preview features

  5. Test Thoroughly: Especially for applications using JNI or sun.misc.Unsafe

  6. Performance Testing: Verify GC behavior with new ZGC defaults

Code Review Checklist

When reviewing code for Java 25 upgrade:

  • [ ] Replace ASM usage with Class-File API

  • [ ] Convert complex HTML JavaDoc to Markdown

  • [ ] Use primitive patterns in switch expressions where applicable

  • [ ] Replace sun.misc.Unsafe with VarHandle or FFM API

  • [ ] Add native-access permissions for JNI usage

  • [ ] Use Stream gatherers for complex stream operations

  • [ ] Update build configuration for preview features

Testing Considerations
  • Test with --enable-preview flag for preview features

  • Verify JNI applications work with native access warnings

  • Performance test with new ZGC generational mode

  • Validate JavaDoc generation with Markdown comments

Common Pitfalls

  1. Preview Feature Dependencies: Don't use preview features in library code without clear documentation

  2. Native Access: Applications using JNI directly or indirectly may need --enable-native-access configuration

  3. Unsafe Migration: Don't delay migrating from sun.misc.Unsafe - deprecation warnings indicate future removal

  4. Pattern Matching Scope: Primitive patterns work with all primitive types, not just int

  5. Record Enhancement: Derived record creation (with expressions) is not available in any JDK 25 mode; use explicit withX copy methods

Performance Considerations

  • ZGC generational mode may improve performance for most workloads

  • Class-File API reduces ASM-related overhead

  • Stream gatherers provide better performance for complex stream operations

  • G1GC improvements reduce JIT compilation overhead

Remember to test thoroughly in staging environments before deploying Java 25 upgrades to production systems.

Requirements and compatibility

Written for: GitHub Copilot

Works with: Claude Code, Claude apps, OpenAI Codex, GitHub Copilot, Cursor, Gemini CLI, Kiro, OpenCode, Goose, Amp, Roo Code, JetBrains Junie, Factory Droid, Devin (ex-Windsurf), Mistral Vibe, OpenHands, Letta

“Works with” means the tool reads the open Agent Skills format; a skill written for one tool may use features others lack.

Needs: Needs Node.js

Security

What our scanner noticed· Low risk

  • Instructions that use the network

A static scan is not a guarantee. Skills are third-party content: review a skill before you let an agent use it.

Attribution and licence

First committed by
GitHub avatar of jduboisjdubois
Publisher
GitHub (Official)
Distributed by
GitHub
Source
github/awesome-copilot · skills/java-upgrade · commit 797337f
Licence
MIT License (redistribution allowed)
  • LICENSE (added by AutoGineer from LICENSE)
  • ATTRIBUTION.md (written by AutoGineer)
Synced
Contributors
jdubois

AutoGineer is not affiliated with or endorsed by jdubois or GitHub.

Download ZIP

The ZIP holds the skill’s files, its licence files and an ATTRIBUTION.md. Download java-upgrade.zip