Get the FREE Ultimate OpenClaw Setup Guide →

110-java-maven-best-practices

Scanned
npx machina-cli add skill jabrena/cursor-rules-java/110-java-maven-best-practices --openclaw
Files (1)
SKILL.md
1.8 KB

Maven Best Practices

Improve Maven POM configuration using industry-standard best practices.

Core areas: 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, and cross-module version consistency.

Prerequisites: Run ./mvnw validate or mvn validate before applying recommendations. If validation fails, stop and ask the user to fix issues—do not proceed until resolved.

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.

Before applying changes: Read the reference for detailed examples, good/bad patterns, and constraints.

Reference

For detailed guidance, examples, and constraints, see references/110-java-maven-best-practices.md.

Source

git clone https://github.com/jabrena/cursor-rules-java/blob/main/skills/110-java-maven-best-practices/SKILL.mdView on GitHub

Overview

Provides a concise blueprint to review, improve, or troubleshoot Maven pom.xml files. It highlights dependency management with BOMs, plugin configuration, version centralization, environment build profiles, and a clean multi-module structure to ensure consistency and maintainability.

How This Skill Works

Start with the root pom and check for modules; if present, inspect each child pom for hardcoded versions or redundant pluginManagement blocks. Validate the project with mvn validate before applying recommendations, and implement changes using centralized version properties and a shared dependencyManagement BOM so modules inherit consistent versions.

When to Use It

  • Auditing an existing project to remove version drift across modules.
  • Introducing BOMs and dependencyManagement to standardize dependencies.
  • Centralizing plugin versions with pluginManagement in the parent POM.
  • Setting up or refining a multi-module project with proper inheritance.
  • Adding environment-specific build profiles for reproducible dev/stage/prod builds.

Quick Start

  1. Step 1: Run mvn validate to establish a clean baseline.
  2. Step 2: Review the root pom for dependencyManagement, pluginManagement, properties, and modules; identify hardcoded versions.
  3. Step 3: Move versions into centralized properties and a parent dependencyManagement BOM, then re-run mvn validate and mvn package.

Best Practices

  • Use dependencyManagement and BOMs to centralize dependency versions.
  • Centralize versions via properties in the parent POM rather than duplicating in modules.
  • Define pluginManagement in the root to standardize plugin versions across modules.
  • Keep a readable POM structure and avoid hardcoding versions in child modules.
  • Audit multi-module projects for proper inheritance and cross-module version consistency.

Example Use Cases

  • Root POM imports a BOM like spring-boot-dependencies to manage all dependencies.
  • Child modules stop hardcoding versions and rely on parent dependencyManagement.
  • Maven plugins are controlled via pluginManagement with centralized versions.
  • Build profiles for dev, test, and prod are declared in the root POM with explicit activation criteria.
  • The root POM lists all modules and ensures consistent version drift checks across modules.

Frequently Asked Questions

Add this skill to your agents
Sponsor this space

Reach thousands of developers