110-java-maven-best-practices

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Maven Best Practices

Maven最佳实践

Improve Maven POM configuration using industry-standard best practices.
What is covered in this Skill?
  • Dependency management via
    <dependencyManagement>
    and BOMs
  • Standard directory layout (
    src/main/java
    ,
    src/test/java
    )
  • Centralized plugin management
  • Build profiles for environment-specific settings
  • Readable POM structure with version properties
  • Explicit repository declaration
  • Version centralization
  • Multi-module project structure with proper inheritance
  • Cross-module version consistency
  • Multi-module scope: After reading the root
    pom.xml
    , check for a
    <modules>
    section. If present, read every child module's
    pom.xml
    before making any recommendations.
  • Check each child for hardcoded versions that duplicate parent
    <dependencyManagement>
    , redundant
    <pluginManagement>
    blocks, properties that should be centralized, and version drift across sibling modules.
使用行业标准的最佳实践改进Maven POM配置。
本技能涵盖哪些内容?
  • 通过
    <dependencyManagement>
    和BOM进行依赖管理
  • 标准目录结构(
    src/main/java
    src/test/java
  • 集中式插件管理
  • 针对特定环境设置的构建配置文件
  • 使用版本属性实现可读性强的POM结构
  • 显式声明仓库
  • 版本集中管理
  • 具有正确继承关系的多模块项目结构
  • 跨模块版本一致性
  • 多模块范围:读取根
    pom.xml
    后,检查是否存在
    <modules>
    部分。如果存在,在提出任何建议前需读取所有子模块的
    pom.xml
  • 检查每个子模块中是否存在重复父模块
    <dependencyManagement>
    的硬编码版本、冗余的
    <pluginManagement>
    块、应集中管理的属性,以及兄弟模块间的版本差异。

Constraints

约束条件

Before applying Maven best practices recommendations, ensure the project is in a valid state by running Maven validation. This helps identify any existing configuration issues that need to be resolved first. For multi-module projects, scope analysis must cover every child module POM — not just the root.
  • MANDATORY: Run
    ./mvnw validate
    or
    mvn validate
    before applying any Maven best practices recommendations
  • VERIFY: Ensure all validation errors are resolved before proceeding with POM modifications
  • SAFETY: If validation fails, do not continue and ask the user to fix the issues before continuing
  • MULTI-MODULE DISCOVERY: After reading the root
    pom.xml
    , check whether it contains a
    <modules>
    section. If it does, read every child module's
    pom.xml
    before making any recommendations — analysis scope is the full module tree, not only the root
  • CROSS-MODULE SCOPE: When child modules exist, check each one for: hardcoded dependency versions that duplicate
    <dependencyManagement>
    in the parent, plugin configurations that duplicate
    <pluginManagement>
    , properties that should be centralized in the parent, and version drift (same artifact declared at different versions across sibling modules)
  • BEFORE APPLYING: Read the reference for detailed examples, good/bad patterns, and constraints
在应用Maven最佳实践建议之前,需通过运行Maven验证确保项目处于有效状态。这有助于识别任何需要先解决的现有配置问题。对于多模块项目,分析范围必须覆盖所有子模块的POM——而不仅仅是根POM。
  • 强制要求:在应用任何Maven最佳实践建议之前,运行
    ./mvnw validate
    mvn validate
  • 验证:在进行POM修改之前,确保所有验证错误均已解决
  • 安全要求:如果验证失败,请勿继续操作,需要求用户先解决问题
  • 多模块发现:读取根
    pom.xml
    后,检查它是否包含
    <modules>
    部分。如果包含,在提出任何建议前需读取所有子模块的
    pom.xml
    ——分析范围是整个模块树,而非仅根模块
  • 跨模块范围:当存在子模块时,检查每个子模块是否存在:重复父模块
    <dependencyManagement>
    的硬编码依赖版本、重复
    <pluginManagement>
    的插件配置、应在父模块中集中管理的属性,以及版本差异(同一构件在兄弟模块中声明的版本不同)
  • 应用前:查阅参考文档获取详细示例、优劣模式及约束条件

When to use this skill

何时使用本技能

  • Review pom.xml to improve it
  • Apply Maven best practices to pom.xml
  • Improve Maven POM configuration
  • 审查并改进pom.xml
  • 对pom.xml应用Maven最佳实践
  • 改进Maven POM配置

Reference

参考文档

For detailed guidance, examples, and constraints, see references/110-java-maven-best-practices.md.
如需详细指南、示例及约束条件,请参阅references/110-java-maven-best-practices.md