# Add the Maven Enforcer Plugin to a Build

Yes. An agent adds maven-enforcer-plugin with version, convergence and duplicate rules tuned to the project's JDK matrix, verifies on each JDK and opens a PR.

[Run this on Rush](https://cloud.getrush.ai/run/add-enforcer-plugin/maven/). Opens the console with this prompt ready to send, in a Project that has your repository.

## What the agent does

The agent reads the POM before choosing rules. In a project laid out like jhy/jsoup, `pom.xml` builds `org.jsoup:jsoup` with a long, fully pinned plugin list: `maven-compiler-plugin` 3.16.0 with a `compile-package-info` execution at source and target 8, `animal-sniffer-maven-plugin` 1.28 checking the Java 8 and Android 21 API signatures, `maven-javadoc-plugin` 3.12.0, `maven-source-plugin` 3.4.0, `maven-jar-plugin` 3.5.1, `maven-bundle-plugin` 5.1.9, `maven-surefire-plugin` and `maven-failsafe-plugin` 3.6.0, `japicmp-maven-plugin` 0.26.3 and `central-publishing-maven-plugin` 0.11.0. Profiles activate by JDK: `java-8` on `1.8`, `multi-release` on `[11,2000)` with `build-helper-maven-plugin` 3.6.2 adding `src/test/java11`. Dependencies are `junit-jupiter` 5.14.4, `gson` 2.14.0, two Netty artifacts versioned through an imported `netty-bom` 4.2.19.Final, `jspecify` 1.0.1 as `provided` and `re2j` 1.8. There is no Maven wrapper. `.github/workflows/build.yml` runs `mvn -B compile` and `mvn -B verify` on a matrix of Ubuntu, Windows and macOS with JDK 8, 17 and 25 from Zulu, and `.github/dependabot.yml` updates Maven dependencies weekly with a 12-day cooldown, ignoring the JUnit 6 major because it needs JDK 17.

Those facts set the rules. The agent adds `maven-enforcer-plugin` 3.6.3 to `<build><plugins>` with one `enforce` execution, which binds to the `validate` phase by default so it runs before compilation on every `mvn verify`. `requireMavenVersion` is set to `[3.6.3,)`, the floor current plugins need; `requireJavaVersion` to `[1.8,)`, because the matrix still builds on 8 and a higher floor would break that leg; `requirePluginVersions` with `banLatest`, `banRelease` and `banSnapshots`, which the POM already satisfies and which Dependabot's weekly updates keep true; `banDuplicatePomDependencyVersions`; and `dependencyConvergence` plus `requireUpperBoundDeps`, which pass today because the Netty BOM aligns the two Netty artifacts and JUnit's aggregator pins its own modules, and which will catch the first update that pulls two versions of one transitive library. `banDynamicVersions` is left out and explained: the project's own `1.24.1-SNAPSHOT` version is normal for a library between releases and the rule is about dependencies, but a test-scoped range would trip it, so the reviewer decides.

Rules are only useful if they pass, so the agent runs `mvn -B verify` on the same JDKs the workflow uses, installing 8, 17 and 25 in the sandbox, and reads the enforcer summary on each. A rule that fails on one JDK is either tuned (the Java 8 leg is where a floor set too high shows up) or reported with the exact message rather than loosened without comment. It also runs `mvn -B enforcer:enforce -Denforcer.fail=false` once to show every rule's verdict as warnings in the pull request, and confirms `-Denforcer.skip` still bypasses the plugin for a local experiment.

Because Dependabot already covers the `maven` ecosystem, the new plugin's updates arrive through the existing weekly pull requests with no change to `dependabot.yml`, and the agent notes that `japicmp`, `animal-sniffer` and the enforcer are three different checks: API compatibility, API surface, and build hygiene.

## Start it with one API call

`POST https://api.phoenix.so/o/{org}/sessions`

```json
{
  "agent": "claude",
  "input": "Add the Maven Enforcer plugin to this project's build. Read pom.xml in full, including every plugin version, profile activation and dependency, plus .github/workflows/build.yml and .github/dependabot.yml first. Add maven-enforcer-plugin at its current release with one enforce execution and rules chosen from what the build already guarantees: a Maven version floor, a Java version floor that keeps the oldest JDK in the CI matrix building, requirePluginVersions banning LATEST, RELEASE and snapshots, banDuplicatePomDependencyVersions, dependencyConvergence and requireUpperBoundDeps. Explain any rule you leave out. Install the JDKs the workflow matrix uses and run mvn -B verify on each, tune a rule only when it fails for a reason you can state, show every rule's verdict with enforcer.fail=false, and open a pull request that lists each rule with why it is set at that value and quotes the verify summary per JDK.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app"
    }
  ]
}
```

1. **Get an API key.** In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
2. **Send the request.** POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
3. **Read what came back.** Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

## What comes back

The pull request changes `pom.xml` only, adding one plugin block of about forty lines. Its description lists each rule with the value and the reason, quotes the `mvn -B verify` summary from each JDK the agent ran, and names the rules it considered and left out, with the condition under which a maintainer might add them.

A reviewer checks the two floors against their release process (a Maven floor above what their release machine has would block a release, not a build), decides on `banDynamicVersions` and whether `dependencyConvergence` should be `WARN` while the first Dependabot updates land, and confirms the JDK 8 leg of the matrix still passes on the pull request's own workflow run.

From then on a dependency update that brings two versions of one library, an unpinned plugin, or a build on an unsupported Maven stops at `validate` with the rule's message instead of surfacing as a test failure three phases later.

## Run it on every Maven project without a build policy

A team with many Maven repositories sends this body once per repository from its own server, each a `POST /o/{org}/sessions` with that repository in `resources` and a `request_id` that is a UUID v5 of the repository's full name, so a retried call returns the run already started. Each run reads its own POM: a multi-module build gets the plugin in the parent with `reactorModuleConvergence` added, a project on JDK 17 only gets a 17 floor, and one with a Maven wrapper gets the Maven floor matched to `maven-wrapper.properties`.

Give the key a `webhook_url` and Rush POSTs `run.completed` to it when each turn ends, signed per Standard Webhooks, with `data.session_url` to read the pull request from. A follow-up on `POST /o/{org}/sessions/{id}/messages`, once the turn has finished, wakes the same sandbox to switch a rule to `WARN` or add `bannedDependencies` for a library the team has retired.

## Why run it on Rush?

The plugin block is easy; the judgement is in reading the POM and the CI matrix closely enough to set floors that match them, and then proving every rule passes on every JDK the project supports. The agent installs those JDKs in its own sandbox, runs the full `verify` on each, and quotes the summaries, so the reviewer sees the rules' verdicts rather than inferring them.

For an organisation standardising its Maven builds, the same request runs against every repository at once and each run derives its floors from that repository's own workflow and plugins, which is what makes the resulting pull requests both uniform and correct.

## Frequently asked questions

### Why a Java floor of 1.8 rather than 17?

Because the workflow still builds and tests on JDK 8, and `requireJavaVersion` runs on the JDK that executes Maven. A floor of 17 would fail that leg of the matrix on every push. When the project drops Java 8, the floor moves with it, and the pull request says so.

### Will dependencyConvergence break Dependabot updates?

It will block the ones that introduce a split, which is the intent: an update that brings two versions of one transitive library stops at `validate` with the paths listed. For a project that expects a noisy period, the rule can carry `<level>WARN</level>` at first, and the agent leaves that line commented in the block so switching is one edit.

### Does this duplicate what japicmp and animal-sniffer do?

No. japicmp compares the new jar's API with the previous release, animal-sniffer checks that the code uses only Java 8 and Android 21 APIs, and the enforcer checks the build itself: versions of Maven, the JDK, the plugins and the dependency graph. The three run at different phases and catch different mistakes.

### Can I skip it locally?

Yes, with `-Denforcer.skip`, or run only the checks with `mvn enforcer:enforce`, or see every verdict without failing with `-Denforcer.fail=false`. The agent runs that last form in the sandbox so the pull request shows each rule's result, not only that the build passed.

## More Maven jobs

- [Add Error Prone to a Maven Build](https://getrush.ai/run/add-errorprone/maven/)
- [Add JaCoCo Code Coverage to a Maven Project](https://getrush.ai/run/add-jacoco-coverage/maven/)
- [Add the Maven Wrapper to a Maven Project](https://getrush.ai/run/add-maven-wrapper/maven/)

## More jobs like this: Hand off a long task

- [Convert a String Column to a PostgreSQL Enum With sqlc](https://getrush.ai/run/add-enum-types/sqlc/)
- [Move Hard-Coded Values in a Compose File into a .env File](https://getrush.ai/run/add-env-file/docker-compose/)
- [Read Typer CLI Options From Environment Variables](https://getrush.ai/run/add-env-var-options/typer/)

## Keep reading

- [How a Rush run works on your repository, from request to pull request](https://getrush.ai/cloud/)
- [Compare cloud agents, agent sandboxes and AI code review](https://getrush.ai/compare/)
- [Rush pricing: Free, Pro and Max](https://getrush.ai/pricing/)
