Repository navigation
Description
Summary
EnforceMojo declares requiresDependencyCollection = ResolutionScope.TEST unconditionally:
@Mojo(
name = "enforce",
defaultPhase = LifecyclePhase.VALIDATE,
requiresDependencyCollection = ResolutionScope.TEST,
threadSafe = true)This forces Maven's concurrent build scheduler to wait for all upstream reactor modules to complete their package phase before the enforce goal can start — even when the configured rules don't need any dependency information at all.
Impact
In Maven 4's BuildPlanExecutor, any mojo with a non-null dependencyCollectionRequired or dependencyResolutionRequired in its descriptor triggers this constraint (see BuildPlanExecutor.java):
if (descriptor.getDependencyCollectionRequired() != null
|| descriptor.getDependencyResolutionRequired() != null) {
for (MavenProject upstream : plan.getAllProjects().get(step.project)) {
plan.step(upstream, AFTER + PACKAGE).ifPresent(executionStep::executeAfter);
}
}Since enforce runs in the validate phase by default, this means every parallel module stalls on its upstream siblings finishing package before validation can even begin — a worst-case scheduling barrier applied regardless of configured rules.
Per-rule analysis
The built-in rules span a wide range of actual dependency access:
NOTHING — no dependency access (environment/filesystem checks)
AlwaysPass, AlwaysFail, RequireOS, RequireJavaVendor, RequireJavaVersion, RequireMavenVersion, RequireEnvironmentVariable, EvaluateBeanshell, EvaluateGroovy, BanPropertyPrefix, RequireFilesExist, RequireFilesDontExist, RequireFileChecksum, RequireTextFileChecksum
POM_ONLY — raw/effective model, no graph resolution
RequireReleaseVersion, RequireSnapshotVersion, RequireMatchingCoordinates, BanDistributionManagement, BannedRepositories, RequireNoRepositories, BanDuplicatePomDependencyVersions, BanDependencyManagementScope, RequireExplicitDependencyScope, ReactorModuleConvergence, BannedPlugins, RequireActiveProfile, RequireProfileIdsExist, RequirePrerequisite, RequireProperty
COLLECT — dependency graph (conflict-resolved versions), no artifact files
BanTransitiveDependencies, DependencyConvergence, RequireUpperBoundDeps, BanDynamicVersions, RequireReleaseDeps (when searchTransitive=true), BannedDependencies (when searchTransitive=true)
RESOLVE — artifact files on disk
EnforceBytecodeVersion (reads JAR bytecode via ClassReader), RequireFilesSize (checks artifact file size), RequirePluginVersions (calls RepositorySystem.resolveArtifact() for version lookup)
The vast majority of common rule configurations need NOTHING or POM_ONLY. Only EnforceBytecodeVersion, RequireFilesSize, and RequirePluginVersions genuinely need RESOLVE. The COLLECT rules do their own graph traversal internally via ResolverUtil.collectDependencies() — they don't depend on the mojo-level scope to populate MavenProject.getArtifacts().
Why simple fixes don't work
- Lower the annotation to
NONE: breaksEnforceBytecodeVersionandRequireFilesSizefor intra-reactor dependencies —ReactorReader.findArtifact()returnstarget/classesornullfor unpackaged reactor modules, and reading bytecode from a directory instead of a JAR fails for multi-release jars and classifiers - Add a
<resolutionScope>parameter: only affects resolution at execution time, not scheduling — the barrier is baked into the build plan before any parameter is read - Split into multiple goals: leads to 3 goals (none/collect/resolve), confusing UX, and still requires users to know which rules need which scope
- Per-rule API (
getResolutionScope()onEnforcerRuleBase): useful for documentation but cannot retroactively affect scheduling — the build plan is constructed before rule classes are instantiated
Proposed fix (depends on apache/maven enhancement)
A companion issue has been filed on the Maven core project: apache/maven#NNNN — Allow plugin descriptor to reference plugin configuration for dependency resolution scope.
If Maven supports referencing a configuration property in the descriptor's requiresDependencyCollection / requiresDependencyResolution field (with property interpolation at plan-construction time), the enforcer can:
- Declare
requiresDependencyCollection = "@{dependencyScope:test}"in the annotation (defaulttestfor backward compatibility) - Users who only use NOTHING/POM rules configure:
...and the scheduling barrier is eliminated for that execution
<configuration> <dependencyScope>none</dependencyScope> </configuration>
Until that Maven enhancement lands, the status quo is maintained (no regression). When it lands, enforcer adopts the new descriptor syntax in a 4.x release.
Workaround (today)
Users who know they only use non-dependency rules and want parallel builds to be unblocked can bind the enforcer to a later phase (e.g., verify) where the barrier cost is irrelevant, or disable the enforcer for large concurrent builds.
Activity
gnodet commentedon Nov 30, 2026
The companion Maven core issue has been filed: apache/maven#14194
The enforcer fix is blocked on that landing first.