Share via


Quickstart: upgrade a Java project with GitHub Copilot App Modernization - upgrade for Java

This quickstart shows you how to upgrade a Java project using GitHub Copilot App Modernization - upgrade for Java.

Prerequisites

Note

If you're using Gradle, only the Gradle wrapper version 5+ is supported. The Kotlin DSL isn't supported.

Sign in to use Copilot and then install the required extension

To use GitHub Copilot, sign in to your GitHub account in Visual Studio Code. Select the Copilot icon at the top of Visual Studio Code to access the GitHub Copilot pane. For more information about setting up GitHub Copilot, see Set up GitHub Copilot in VS Code.

Then, use the following steps to install the extension in Visual Studio Code:

  1. In Visual Studio Code, open the Extensions view from the Activity Bar.
  2. Search for GitHub Copilot App Modernization in the marketplace.
  3. Select the GitHub Copilot App Modernization extension pack.
  4. On the extension page, select Install.
  5. Restart Visual Studio Code.

After installation completes, you should see a notification in the corner of Visual Studio Code confirming success.

For more information, see Install a VS Code extension.

Select a Java project to upgrade

For the purposes of this tutorial, choose one of the following sample repositories:

Launch GitHub Copilot Agent Mode and start the upgrade

Use the following steps to launch GitHub Copilot Agent Mode and start the upgrade process:

  1. Open the selected Java project in Visual Studio Code.

  2. Open the GitHub Copilot Chat panel.

  3. Switch to Agent Mode.

  4. Enter a prompt such as Upgrade project to Java 21 using Java upgrade tools or Upgrade project to Java 21 and Spring Boot 3.2 using Java upgrade tools to include framework information.

    Note

    If you need to upgrade a framework or third-party dependency only, see Upgrade a framework or third-party dependency by using GitHub Copilot App Modernization – upgrade for Java.

  5. When prompted, select Continue to generate an upgrade plan.

Screenshot of Visual Studio Code that shows an example upgrade plan.

Review and edit the upgrade plan

App Modernization - upgrade for Java analyzes the Java project in the current workspace, including its JDK, build tools, and dependencies. The tool generates a plan.md file that outlines the following planned changes:

  • Source and target JDK versions.
  • Framework and library upgrade paths.

Review the plan and make changes if needed, then select Continue to proceed. For information about further customization, such as adding more build tool parameters, see Customize the upgrade plan.

Tip

Ensure that the plan matches your desired upgrade targets - for example, Java 8 to Java 21, Spring Boot 2.7 to 3.2.

Screenshot of Visual Studio Code that shows an example upgrade plan with upgrade targets highlighted.

Apply code changes and fix build issues

GitHub Copilot then proceeds with the code transformation phase of the project. It uses an open-source tool called OpenRewrite to implement some code changes based on specific recipes. Then, AI addresses the remaining issues through a dynamic build/fix loop. You can monitor progress in the editor area of Visual Studio Code by checking the progress.md markdown file at any time.

At various stages of the process, GitHub Copilot prompts you to continue.

For the Confirm the OpenRewrite transformation step, select Continue to upgrade Java code using OpenRewrite. This step might take a few minutes.

For the Approve the dynamic build/fix loop step, select Continue to build the project and fix errors.

Copilot iterates and continues to fix errors until there are no more issues. Progress is shown in a progress.md file. The loop continues until the project builds successfully.

Screenshot of Visual Studio Code that shows the GitHub Copilot chat pane with Build-Fix output and the Continue button highlighted.

Check for vulnerabilities and code behavior changes

Under certain circumstances, the upgrade might cause code behavior changes or introduce libraries with Common Vulnerabilities and Exposures (CVE) issues. The tool performs an extra check for these issues.

When GitHub Copilot prompts Run Validate if any modified dependencies have known CVEs, select Continue.

If CVEs are found, GitHub Copilot Agent Mode attempts to fix them. Review the changes in VS Code and decide whether to keep them.

Screenshot of Visual Studio Code that shows the GitHub Copilot chat pane with CVE output and the Continue button highlighted.

After the CVE check, when prompted to Run Validate code behavior consistency, select Continue.

If issues are found, GitHub Copilot Agent Mode tries to resolve them. Decide whether to keep or discard the changes.

After the checks complete, GitHub Copilot rebuilds the project and reruns the previous checks.

If minor issues remain that don't require immediate fixes, the upgrade is complete. Otherwise, GitHub Copilot goes back to address them.

Screenshot of Visual Studio Code that shows the editor with a fixed line.

View the summary

After the upgrade, the tool generates a summary in the summary.md file, which includes the following information:

  • Project information.
  • Lines of code changed.
  • Updated dependencies.
  • Summarized code changes.
  • Fixed CVE security and code inconsistency issues, if any.
  • Unaddressed minor CVE issues.

Screenshot of Visual Studio Code that shows the Upgrade Java Project summary content.

Next step

Quickstart: generate unit tests with GitHub Copilot App Modernization - upgrade for Java