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

   ## Summary
   
   Allow a plugin descriptor's `requiresDependencyCollection` / 
`requiresDependencyResolution` field to reference a plugin configuration 
property, interpolated at build-plan construction time, so that the scheduling 
barrier applied by the concurrent builder can be tuned per-execution without 
forking goals or changing the descriptor statically.
   
   ## Motivation
   
   The concurrent builder in `BuildPlanExecutor` gates a mojo's execution on 
upstream reactor modules completing `package` whenever the mojo descriptor 
declares a non-null dependency scope:
   
   ```java
   if (descriptor.getDependencyCollectionRequired() != null
           || descriptor.getDependencyResolutionRequired() != null) {
       for (MavenProject upstream : plan.getAllProjects().get(step.project)) {
           plan.step(upstream, AFTER + 
PACKAGE).ifPresent(executionStep::executeAfter);
       }
   }
   ```
   
   This barrier is determined once, statically, at plan construction time — 
before any mojo is instantiated or any `@Parameter` is read. A plugin cannot 
currently make this barrier conditional on its own configuration.
   
   A concrete case: `maven-enforcer-plugin` (see apache/maven-enforcer#1098). 
It declares `requiresDependencyCollection = TEST` as a worst-case default, but 
most users configure only rules that need no dependency access (OS checks, Java 
version, POM metadata). The barrier is a pure waste for them. The plugin cannot 
safely lower the annotation to `NONE` because a minority of rules 
(`EnforceBytecodeVersion`, `RequireFilesSize`) genuinely need the barrier for 
correctness with intra-reactor dependencies.
   
   ## Proposed solution
   
   ### 1. Descriptor-level config property reference
   
   Extend the `plugin.xml` descriptor (and the corresponding annotation) to 
allow a configuration property reference in the scope fields, with an optional 
default:
   
   ```
   requiresDependencyCollection = "@{propertyName:defaultValue}"
   ```
   
   For example, in `EnforceMojo`:
   
   ```java
   @Mojo(
       name = "enforce",
       defaultPhase = LifecyclePhase.VALIDATE,
       requiresDependencyCollection = "@{dependencyScope:test}",
       threadSafe = true)
   ```
   
   ### 2. Interpolation at plan construction time
   
   In `BuildPlanExecutor`, before the barrier check, resolve config-property 
references by looking up the key in `execution.getConfiguration()` (the merged 
`Xpp3Dom` from the POM's `<configuration>` block):
   
   ```java
   String collectionScope = resolveDescriptorScope(
       descriptor.getDependencyCollectionRequired(),
       execution.getConfiguration());
   String resolutionScope = resolveDescriptorScope(
       descriptor.getDependencyResolutionRequired(),
       execution.getConfiguration());
   
   if (collectionScope != null || resolutionScope != null) {
       for (MavenProject upstream : plan.getAllProjects().get(step.project)) {
           plan.step(upstream, AFTER + 
PACKAGE).ifPresent(executionStep::executeAfter);
       }
   }
   ```
   
   Where `resolveDescriptorScope` strips the `@{...}` syntax, looks up the 
child node by name in the `Xpp3Dom`, and returns `null` (no barrier) if the 
resolved value is `"none"` or `""`.
   
   ### 3. Notes on interpolation scope
   
   `execution.getConfiguration()` at plan-construction time is the merged POM 
configuration **before** Maven property interpolation (i.e., 
`${project.version}` is not yet resolved). This is acceptable and even 
desirable here: the value should be a literal scope name (`none`, `compile`, 
`test`), not a computed value. If Maven property interpolation is needed in 
future, that can be added separately.
   
   ### 4. Backward compatibility
   
   - Descriptors with literal scope values (current behavior) are unaffected — 
the `@{...}` prefix is unambiguous
   - Plugins that don't use the new syntax behave identically to today
   - The default value in `@{propertyName:defaultValue}` ensures 
backward-compatible behavior when users don't configure the property
   
   ## Plugin tool support
   
   `maven-plugin-plugin` should recognize the `@{...}` syntax in 
`@Mojo(requiresDependencyCollection = ...)` and emit it as-is into 
`plugin.xml`, generating a corresponding `@Parameter` stub or at least a note 
in the generated Mojo documentation indicating which configuration value 
controls the scheduling barrier.
   
   ## Related
   
   - apache/maven-enforcer#1098 — the concrete use case driving this request
   


-- 
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