跳到正文
Skillpedia
API 与服务器(后端)40k · #7261

java-upgrade

它能做什么

帮你把 Java 项目升级到更新的 Java 版本(比如从 11 升级到 17)。它会一步步引导你安全地使用新的语言特性和库功能。

适用场景

  • ✓当你想把 Java 代码更新到更新的版本时。
  • ✓当你想让 Java 项目用上更现代的写法时。
  • ✓当你想使用“records”或“sealed classes”等新特性时。

技能链接

https://github.com/github/awesome-copilot/blob/main/skills/java-upgrade/SKILL.md

复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。

使用方法

最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/github/awesome-copilot/blob/main/skills/java-upgrade/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 AI

“我想把 Java 项目从 11 升级到 17,并使用其中的新特性。”

每周 5 个新技能,1 分钟读完。

工作原理

AI 会先检查你的项目使用的是哪个 Java 版本,然后逐个版本引导你完成必要的修改。它会建议如何更新构建系统,之后再帮你引入新的语言特性。

技术内容(原始 SKILL.md)

作者在 GitHub 上的英文原文。

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

Upgrade Guide
Java 11 → 17 references/java-11-to-17.md
Java 17 → 21 references/java-17-to-21.md
Java 21 → 25 references/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.
常见问题

这个技能和“modernize-java”插件有什么区别?

这个技能提供的是更简单的分步指南。“modernize-java”插件是功能更强大的工具,可以自动完成更复杂的升级,需要单独安装。

什么是“records”和“sealed classes”?

“Records”是一种更简洁的类写法,专门用来存放数据。“Sealed classes”(密封类)则可以控制哪些类能够继承某个类。

可以跳过中间的 Java 版本直接升级吗?

不建议这样做。AI 会建议每次只升级一个主版本(例如先从 11 升到 17,再从 17 升到 21),确保每一步都能正常运行。

详情

作者的原始描述

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-e

repo: github/awesome-copilot

热度

GitHub 星标
40k
排名
#7261
许可证
MIT
更新时间
2026/10/15

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能