Maven Enforcer Rule Failed in CI - Satisfy or Fix the Rule
maven-enforcer-plugin fails the build when a declared rule is violated - a wrong Java/Maven version, a banned or duplicate dependency, or version convergence problems. It is a deterministic policy gate that fails identically until the underlying condition is met.
What this error means
The build fails with Some Enforcer rules have failed and a specific rule message: requireJavaVersion ... Detected JDK version 11 ... is not in the allowed range [17,), a banned dependency, or convergence errors.
[WARNING] Rule 0: org.apache.maven.enforcer.rules.version.RequireJavaVersion failed with message:
Detected JDK version 11.0.22 is not in the allowed range [17,).
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-enforcer-plugin:3.5.0:enforce
(enforce) on project app: Some Enforcer rules have failed.Common causes
Environment violates a version rule
requireJavaVersion/requireMavenVersion fail when the runner JDK or Maven is outside the allowed range.
Dependency rule violated
bannedDependencies, dependencyConvergence, or requireUpperBoundDeps flag conflicting or forbidden artifacts in the tree.
How to fix it
Satisfy a version rule by provisioning the right JDK
Install the version the rule demands rather than weakening the rule.
- uses: actions/setup-java@v4
with:
distribution: temurin
java-version: '17' # match requireJavaVersion [17,)
- run: mvn -B verifyResolve dependency-rule violations
- For convergence, pin the conflicting library to one version (often via a BOM) so the tree converges.
- For banned dependencies, exclude the forbidden transitive artifact.
- Run
mvn enforcer:enforcelocally to see exactly which rule and artifact failed.
How to prevent it
- Match the runner JDK/Maven to enforcer ranges, align dependency versions via a BOM, and keep enforcer rules in sync with the project's real requirements.