gnodet opened a new issue, #1098:
URL: https://github.com/apache/maven-enforcer/issues/1098

   ## Summary
   
   `EnforceMojo` declares `requiresDependencyCollection = ResolutionScope.TEST` 
unconditionally:
   
   ```java
   @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`](https://github.com/apache/maven/blob/master/impl/maven-core/src/main/java/org/apache/maven/lifecycle/internal/concurrent/BuildPlanExecutor.java)):
   
   ```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`**: breaks `EnforceBytecodeVersion` and 
`RequireFilesSize` for intra-reactor dependencies — 
`ReactorReader.findArtifact()` returns `target/classes` or `null` for 
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()` on `EnforcerRuleBase`)**: 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:
   
   1. Declare `requiresDependencyCollection = "@{dependencyScope:test}"` in the 
annotation (default `test` for backward compatibility)
   2. Users who only use NOTHING/POM rules configure:
      ```xml
      <configuration>
        <dependencyScope>none</dependencyScope>
      </configuration>
      ```
      ...and the scheduling barrier is eliminated for that execution
   
   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.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to