2025年9月24日水曜日

Modernizing Java Projects with GitHub Copilot Agent Mode: A Step-by-Step Guide

 Modernizing legacy Java applications can feel like trying to fix a plane mid-flight — especially when you're juggling outdated dependencies, deprecated APIs, or prepping for a cloud migration. But there’s good news: GitHub Copilot agent mode is here to turn that headache into a streamlined, guided workflow.

In this post, you'll learn how to use GitHub Copilot agent mode with the App Modernization for Java extension in VS Code to automatically upgrade, fix, test, and prepare your Java apps for the cloud.

 Bonus: It’s not just for Java — .NET devs using Visual Studio can enjoy a similar guided experience!


 What is GitHub Copilot Agent Mode?

Think of Copilot agent mode as an AI-powered junior developer that doesn’t just suggest code — it understands your goals and carries out multi-step tasks with you.

Instead of typing every little instruction, you can give it a high-level prompt like:

"Upgrade this Java app to Java 21, fix deprecated APIs, and get it cloud-ready."

And just like that, Copilot will:

  • Analyze your code

  • Build an upgrade plan

  • Apply changes

  • Fix build errors

  • Suggest secure dependencies

  • Run tests

  • Even help deploy to Azure

All inside VS Code.


 What You’ll Need Before You Start

To follow along:

  • Visual Studio Code

  • GitHub Copilot license (Pro, Pro+, Business, or Enterprise)

  • GitHub Copilot App Modernization – Java extension

  • A legacy Java project (built with Maven or Gradle, JDK 8+)


 Step-by-Step: Modernizing a Java App with Copilot Agent Mode

Step 1: Open Your Java Project in VS Code

Use your own project or clone a sample:

git clone https://github.com/your-org/your-legacy-java-app.git cd your-legacy-java-app code .

Make sure it's Git-initialized and has a working test suite (unit tests preferred).


Step 2: Start an Agent Session

  • Open the Copilot chat sidebar in VS Code

  • Launch a new Agent Mode session

  • Select: "GitHub Copilot App Modernization – Upgrade for Java"

 Paste this prompt to kick things off:

"Using Java upgrade tools, upgrade this project to Java 21. Analyze deprecated APIs, update Gradle dependencies, and propose a safe, testable migration plan."


Step 3: Let Copilot Analyze & Plan

Copilot will:

  • Scan your JDK usage

  • Review build.gradle or pom.xml

  • Detect deprecated APIs

  • Flag security vulnerabilities (CVEs)

  • Create an upgrade plan (you can edit this!)

 Example output:
A structured upgrade plan in markdown with goals, target JDK version, framework upgrades, and next steps.


Step 4: Apply Upgrades & Resolve Errors

Once you approve the plan, Copilot will:

  • Update Java syntax and imports

  • Apply OpenRewrite transformations

  • Enter a build-test-fix loop until the app compiles and passes tests

 You’ll also get:

  • A change log

  • Commit history

  • API/dependency diff

  • A complete summary report

 Example Code Change

// Before (deprecated) View view = this.resolver.resolveViewName("intro", new Locale("EN")); // After (Java 21) View view = this.resolver.resolveViewName("intro", Locale.of("EN"));

Step 5: Make Your App Azure-Ready

After upgrading, it's time to prepare for the cloud. From the Copilot extension panel:

  1. Click “Migrate to Azure”

  2. Run an App Assessment to identify issues

  3. Configure your deployment target (e.g., AKS) via assessment-config.yaml

Copilot will:

  • Highlight Azure readiness gaps

  • Propose fixes (e.g., migrate from on-prem auth to Microsoft Entra ID)

  • Update dependencies and configs

  • Write documentation

  • Validate everything

 Sample changes include:

  • build.gradle updates (adding Entra ID support)

  • New application.properties entries

  • Custom Spring Security config for Entra ID

  • Markdown docs for dev teams


Step 6: Run Tests & Validate Everything

Once your migration is done, Copilot helps run and validate tests:

 Run manually:

./mvnw test # for Maven ./gradlew test # for Gradle

If any test fails, Copilot can help debug or suggest new tests.

 CVE Scanning

Copilot also performs automatic CVE scans and suggests secure dependency replacements — essential for maintaining compliance.

Example:
No known CVEs found for spring-cloud-azure-starter-active-directory:5.22.0


Step 7: Deploy to Azure (Automatically!)

Once everything checks out, deploy with one click:

  • Provision infrastructure (or use existing)

  • Deploy your app to Azure

  • Get full logs, status, and monitoring setup

 Deployment report includes:

  • 6 Azure resources provisioned

  • Auto-scaling enabled

  • Monitoring via App Insights & Log Analytics

  • Managed identity secured deployment

  • A full deployment record for documentation


 Java Modernization Complete

With GitHub Copilot agent mode and the app modernization extension, you can:

  • Modernize legacy Java apps

  • Automatically fix code issues

  • Validate with tests

  • Scan for CVEs

  • Migrate to the cloud

  • Deploy to Azure

All inside a guided, chat-driven experience in VS Code.


 Try It Today

Whether you’re upgrading Java or migrating .NET, Copilot agent mode is ready to help you:

  • Analyze large codebases

  • Plan upgrades and migrations

  • Execute changes safely

  • Cut hours of manual effort

Learn more in the GitHub Copilot Agent Mode doc

0 件のコメント:

コメントを投稿