This is an automated email from the ASF dual-hosted git repository.

slachiewicz pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-dependency-plugin.git

commit 1b30278bd2f67130893b02337bb993101093924b
Author: Sylwester Lachiewicz <[email protected]>
AuthorDate: Sat Nov 14 00:32:54 2026 +0100

    Resolve processor paths per execution and honour 
annotationProcessorPathsUseDepMgmt
---
 src/it/mrm/repository/mdep907-lib-1.0.jar          | Bin 0 -> 339 bytes
 ...naged-processor-1.0.pom => mdep907-lib-1.0.pom} |   2 +-
 src/it/mrm/repository/mdep907-lib-2.0.jar          | Bin 0 -> 339 bytes
 ...naged-processor-1.0.pom => mdep907-lib-2.0.pom} |   4 +-
 ...r-1.0.jar => mdep907-managed-processor-1.1.jar} | Bin
 ...r-1.0.pom => mdep907-managed-processor-1.1.pom} |   9 +-
 src/it/mrm/repository/mdep907-processor-1.0.pom    |   5 +
 .../pom.xml                                        |  45 ++++--
 .../verify.groovy                                  |  20 ++-
 .../dependency/resolvers/GoOfflineMojo.java        | 100 +++++++-----
 .../dependency/utils/AnnotationProcessorPaths.java | 178 +++++++++++++++------
 src/site/markdown/usage.md.vm                      |   2 +-
 .../utils/AnnotationProcessorPathsTest.java        |  58 ++++++-
 13 files changed, 294 insertions(+), 129 deletions(-)

diff --git a/src/it/mrm/repository/mdep907-lib-1.0.jar 
b/src/it/mrm/repository/mdep907-lib-1.0.jar
new file mode 100644
index 00000000..1bc60544
Binary files /dev/null and b/src/it/mrm/repository/mdep907-lib-1.0.jar differ
diff --git a/src/it/mrm/repository/mdep907-managed-processor-1.0.pom 
b/src/it/mrm/repository/mdep907-lib-1.0.pom
similarity index 94%
copy from src/it/mrm/repository/mdep907-managed-processor-1.0.pom
copy to src/it/mrm/repository/mdep907-lib-1.0.pom
index 06661910..3acd3f6a 100644
--- a/src/it/mrm/repository/mdep907-managed-processor-1.0.pom
+++ b/src/it/mrm/repository/mdep907-lib-1.0.pom
@@ -20,6 +20,6 @@ under the License.
 <project xmlns="http://maven.apache.org/POM/4.0.0";>
   <modelVersion>4.0.0</modelVersion>
   <groupId>org.apache.maven.its.dependency</groupId>
-  <artifactId>mdep907-managed-processor</artifactId>
+  <artifactId>mdep907-lib</artifactId>
   <version>1.0</version>
 </project>
diff --git a/src/it/mrm/repository/mdep907-lib-2.0.jar 
b/src/it/mrm/repository/mdep907-lib-2.0.jar
new file mode 100644
index 00000000..1bc60544
Binary files /dev/null and b/src/it/mrm/repository/mdep907-lib-2.0.jar differ
diff --git a/src/it/mrm/repository/mdep907-managed-processor-1.0.pom 
b/src/it/mrm/repository/mdep907-lib-2.0.pom
similarity index 92%
copy from src/it/mrm/repository/mdep907-managed-processor-1.0.pom
copy to src/it/mrm/repository/mdep907-lib-2.0.pom
index 06661910..564a1a1c 100644
--- a/src/it/mrm/repository/mdep907-managed-processor-1.0.pom
+++ b/src/it/mrm/repository/mdep907-lib-2.0.pom
@@ -20,6 +20,6 @@ under the License.
 <project xmlns="http://maven.apache.org/POM/4.0.0";>
   <modelVersion>4.0.0</modelVersion>
   <groupId>org.apache.maven.its.dependency</groupId>
-  <artifactId>mdep907-managed-processor</artifactId>
-  <version>1.0</version>
+  <artifactId>mdep907-lib</artifactId>
+  <version>2.0</version>
 </project>
diff --git a/src/it/mrm/repository/mdep907-managed-processor-1.0.jar 
b/src/it/mrm/repository/mdep907-managed-processor-1.1.jar
similarity index 100%
rename from src/it/mrm/repository/mdep907-managed-processor-1.0.jar
rename to src/it/mrm/repository/mdep907-managed-processor-1.1.jar
diff --git a/src/it/mrm/repository/mdep907-managed-processor-1.0.pom 
b/src/it/mrm/repository/mdep907-managed-processor-1.1.pom
similarity index 81%
rename from src/it/mrm/repository/mdep907-managed-processor-1.0.pom
rename to src/it/mrm/repository/mdep907-managed-processor-1.1.pom
index 06661910..0b3abe42 100644
--- a/src/it/mrm/repository/mdep907-managed-processor-1.0.pom
+++ b/src/it/mrm/repository/mdep907-managed-processor-1.1.pom
@@ -21,5 +21,12 @@ under the License.
   <modelVersion>4.0.0</modelVersion>
   <groupId>org.apache.maven.its.dependency</groupId>
   <artifactId>mdep907-managed-processor</artifactId>
-  <version>1.0</version>
+  <version>1.1</version>
+  <dependencies>
+    <dependency>
+      <groupId>org.apache.maven.its.dependency</groupId>
+      <artifactId>mdep907-lib</artifactId>
+      <version>1.0</version>
+    </dependency>
+  </dependencies>
 </project>
diff --git a/src/it/mrm/repository/mdep907-processor-1.0.pom 
b/src/it/mrm/repository/mdep907-processor-1.0.pom
index 363fc9b5..84bf24e7 100644
--- a/src/it/mrm/repository/mdep907-processor-1.0.pom
+++ b/src/it/mrm/repository/mdep907-processor-1.0.pom
@@ -23,6 +23,11 @@ under the License.
   <artifactId>mdep907-processor</artifactId>
   <version>1.0</version>
   <dependencies>
+    <dependency>
+      <groupId>org.apache.maven.its.dependency</groupId>
+      <artifactId>mdep907-lib</artifactId>
+      <version>1.0</version>
+    </dependency>
     <dependency>
       <groupId>org.apache.maven.its.dependency</groupId>
       <artifactId>mdep907-processor-dep</artifactId>
diff --git 
a/src/it/projects/mdep-907-go-offline-annotation-processor-paths/pom.xml 
b/src/it/projects/mdep-907-go-offline-annotation-processor-paths/pom.xml
index 07e8b3e7..4a86dc49 100644
--- a/src/it/projects/mdep-907-go-offline-annotation-processor-paths/pom.xml
+++ b/src/it/projects/mdep-907-go-offline-annotation-processor-paths/pom.xml
@@ -31,7 +31,12 @@ under the License.
       <dependency>
         <groupId>org.apache.maven.its.dependency</groupId>
         <artifactId>mdep907-managed-processor</artifactId>
-        <version>1.0</version>
+        <version>1.1</version>
+      </dependency>
+      <dependency>
+        <groupId>org.apache.maven.its.dependency</groupId>
+        <artifactId>mdep907-lib</artifactId>
+        <version>2.0</version>
       </dependency>
     </dependencies>
   </dependencyManagement>
@@ -42,24 +47,30 @@ under the License.
         <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-compiler-plugin</artifactId>
         <version>3.14.1</version>
-        <configuration>
-          <annotationProcessorPaths>
-            <path>
-              <groupId>org.apache.maven.its.dependency</groupId>
-              <artifactId>mdep907-processor</artifactId>
-              <version>1.0</version>
-              <exclusions>
-                <exclusion>
-                  <groupId>org.apache.maven.its.dependency</groupId>
-                  <artifactId>mdep907-excluded-dep</artifactId>
-                </exclusion>
-              </exclusions>
-            </path>
-          </annotationProcessorPaths>
-        </configuration>
+        <!-- the paths are configured in executions only: the model builder 
merges a plugin level <path> into an
+             execution's first <path> by position, which would hide the 
version lookup -->
         <executions>
           <execution>
-            <id>other</id>
+            <id>explicit</id>
+            <phase>none</phase>
+            <configuration>
+              <annotationProcessorPaths>
+                <path>
+                  <groupId>org.apache.maven.its.dependency</groupId>
+                  <artifactId>mdep907-processor</artifactId>
+                  <version>1.0</version>
+                  <exclusions>
+                    <exclusion>
+                      <groupId>org.apache.maven.its.dependency</groupId>
+                      <artifactId>mdep907-excluded-dep</artifactId>
+                    </exclusion>
+                  </exclusions>
+                </path>
+              </annotationProcessorPaths>
+            </configuration>
+          </execution>
+          <execution>
+            <id>managed</id>
             <phase>none</phase>
             <configuration>
               
<annotationProcessorPathsUseDepMgmt>true</annotationProcessorPathsUseDepMgmt>
diff --git 
a/src/it/projects/mdep-907-go-offline-annotation-processor-paths/verify.groovy 
b/src/it/projects/mdep-907-go-offline-annotation-processor-paths/verify.groovy
index 89fede5e..7775ff26 100644
--- 
a/src/it/projects/mdep-907-go-offline-annotation-processor-paths/verify.groovy
+++ 
b/src/it/projects/mdep-907-go-offline-annotation-processor-paths/verify.groovy
@@ -17,22 +17,28 @@
  * under the License.
  */
 
-def assertResolved(String artifactId) {
+def assertResolved(String artifactId, String version) {
     ['jar', 'pom'].each { ext ->
-        File f = new File(localRepositoryPath, 
"org/apache/maven/its/dependency/${artifactId}/1.0/${artifactId}-1.0.${ext}")
+        File f = new File(localRepositoryPath, 
"org/apache/maven/its/dependency/${artifactId}/${version}/${artifactId}-${version}.${ext}")
         assert f.isFile() : "${f} was not resolved"
     }
 }
 
-// configured at plugin level, with a transitive dependency
-assertResolved('mdep907-processor')
-assertResolved('mdep907-processor-dep')
-// configured in an execution, version taken from dependencyManagement
-assertResolved('mdep907-managed-processor')
+// configured in the "explicit" execution, with transitive dependencies
+assertResolved('mdep907-processor', '1.0')
+assertResolved('mdep907-processor-dep', '1.0')
+// not managed for this configuration, so the version the processor declares
+assertResolved('mdep907-lib', '1.0')
+// configured in an execution without a version: 1.1 can only come from 
dependencyManagement
+assertResolved('mdep907-managed-processor', '1.1')
+assert !new File(localRepositoryPath, 
'org/apache/maven/its/dependency/mdep907-managed-processor/1.0').exists()
+// annotationProcessorPathsUseDepMgmt manages the transitive lib of that 
execution to 2.0; both versions must land
+assertResolved('mdep907-lib', '2.0')
 // excluded by the path's exclusions
 assert !new File(localRepositoryPath, 
'org/apache/maven/its/dependency/mdep907-excluded-dep').exists()
 
 String buildLog = new File(basedir, 'build.log').getText('UTF-8')
 assert buildLog.contains('Resolved annotation processor path: 
mdep907-processor-1.0.jar')
+assert buildLog.contains('Resolved annotation processor path: 
mdep907-managed-processor-1.1.jar')
 
 return true
diff --git 
a/src/main/java/org/apache/maven/plugins/dependency/resolvers/GoOfflineMojo.java
 
b/src/main/java/org/apache/maven/plugins/dependency/resolvers/GoOfflineMojo.java
index 0c30b2d5..cf526fa1 100644
--- 
a/src/main/java/org/apache/maven/plugins/dependency/resolvers/GoOfflineMojo.java
+++ 
b/src/main/java/org/apache/maven/plugins/dependency/resolvers/GoOfflineMojo.java
@@ -25,7 +25,10 @@ import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.HashSet;
+import java.util.LinkedHashMap;
+import java.util.LinkedHashSet;
 import java.util.List;
+import java.util.Map;
 import java.util.Set;
 import java.util.function.Predicate;
 import java.util.stream.Collectors;
@@ -66,7 +69,10 @@ import org.sonatype.plexus.build.incremental.BuildContext;
 import static java.util.Optional.ofNullable;
 
 /**
- * Goal that resolves all project dependencies, including plugins and reports 
and their dependencies.
+ * Goal that resolves all project dependencies, including plugins and reports 
and their dependencies. It also
+ * resolves the {@code annotationProcessorPaths} configured for the {@code 
maven-compiler-plugin}, in the plugin
+ * configuration and in each execution, together with their transitive 
dependencies. The scope filters of this goal
+ * treat these paths as compile scope dependencies.
  *
  * @author <a href="mailto:[email protected]";>Brian Fox</a>
  * @author Maarten Mulders
@@ -186,13 +192,7 @@ public class GoOfflineMojo extends 
AbstractDependencyFilterMojo {
                 .map(d -> RepositoryUtils.toDependency(d, 
artifactTypeRegistry))
                 .collect(Collectors.toList());
 
-        List<org.eclipse.aether.graph.Dependency> managedDependencies = 
ofNullable(
-                        getProject().getDependencyManagement())
-                .map(DependencyManagement::getDependencies)
-                .map(list -> list.stream()
-                        .map(d -> RepositoryUtils.toDependency(d, 
artifactTypeRegistry))
-                        .collect(Collectors.toList()))
-                .orElse(null);
+        List<org.eclipse.aether.graph.Dependency> managedDependencies = 
managedDependencies(artifactTypeRegistry);
 
         return getResolverUtil()
                 .resolveDependenciesForArtifact(
@@ -204,47 +204,63 @@ public class GoOfflineMojo extends 
AbstractDependencyFilterMojo {
 
     /**
      * Resolves the {@code annotationProcessorPaths} of the {@code 
maven-compiler-plugin}, which Maven 3 resolves
-     * only when it compiles. The artifact filters of this goal apply to the 
paths; the transitive dependencies of a
-     * path are resolved unless {@code excludeTransitive} is set.
+     * only when it compiles. Each configuration of the compiler plugin is 
resolved on its own, as the compiler does,
+     * and the results are merged. The artifact filters of this goal apply to 
the paths; the transitive dependencies
+     * of a path are resolved unless {@code excludeTransitive} is set.
      */
     private List<org.eclipse.aether.artifact.Artifact> 
resolveAnnotationProcessorPaths()
             throws ArtifactFilterException, ArtifactResolutionException, 
DependencyResolutionException {
-        List<Dependency> paths = AnnotationProcessorPaths.collect(
-                getProject().getBuild().getPlugins(), 
getProject().getDependencyManagement(), getLog()::warn);
-
-        List<Dependency> selected = new ArrayList<>();
-        for (Dependency path : paths) {
-            if 
(!filterDependencies(Collections.singletonList(path)).isEmpty()) {
-                selected.add(path);
-            }
-        }
-        if (selected.isEmpty()) {
-            return Collections.emptyList();
-        }
+        Set<String> warnings = new LinkedHashSet<>();
+        List<AnnotationProcessorPaths.Group> groups = 
AnnotationProcessorPaths.collect(
+                getProject().getBuild().getPlugins(), 
getProject().getDependencyManagement(), warnings::add);
+        warnings.forEach(getLog()::warn);
 
         ArtifactTypeRegistry artifactTypeRegistry =
                 session.getRepositorySession().getArtifactTypeRegistry();
-        List<org.eclipse.aether.graph.Dependency> coordinates = 
selected.stream()
-                .map(d -> RepositoryUtils.toDependency(d, 
artifactTypeRegistry))
-                .collect(Collectors.toList());
-
-        if (excludeTransitive) {
-            return getResolverUtil()
-                    .resolveArtifacts(
-                            coordinates.stream()
-                                    
.map(org.eclipse.aether.graph.Dependency::getArtifact)
-                                    .collect(Collectors.toList()),
-                            getProject().getRemoteProjectRepositories())
-                    .stream()
-                    .map(ArtifactResult::getArtifact)
-                    .collect(Collectors.toList());
+        Map<String, org.eclipse.aether.artifact.Artifact> result = new 
LinkedHashMap<>();
+        for (AnnotationProcessorPaths.Group group : groups) {
+            List<org.eclipse.aether.graph.Dependency> coordinates = new 
ArrayList<>();
+            for (Dependency path : group.getPaths()) {
+                if 
(!filterDependencies(Collections.singletonList(path)).isEmpty()) {
+                    coordinates.add(RepositoryUtils.toDependency(path, 
artifactTypeRegistry));
+                }
+            }
+            if (coordinates.isEmpty()) {
+                continue;
+            }
+            List<org.eclipse.aether.artifact.Artifact> resolved;
+            if (excludeTransitive) {
+                resolved = getResolverUtil()
+                        .resolveArtifacts(
+                                coordinates.stream()
+                                        
.map(org.eclipse.aether.graph.Dependency::getArtifact)
+                                        .collect(Collectors.toList()),
+                                getProject().getRemoteProjectRepositories())
+                        .stream()
+                        .map(ArtifactResult::getArtifact)
+                        .collect(Collectors.toList());
+            } else {
+                resolved = getResolverUtil()
+                        .resolveDependenciesForArtifact(
+                                
RepositoryUtils.toArtifact(getProject().getArtifact()),
+                                coordinates,
+                                group.isUseDependencyManagement() ? 
managedDependencies(artifactTypeRegistry) : null,
+                                getProject().getRemoteProjectRepositories());
+            }
+            for (org.eclipse.aether.artifact.Artifact artifact : resolved) {
+                result.putIfAbsent(artifact.toString(), artifact);
+            }
         }
-        return getResolverUtil()
-                .resolveDependenciesForArtifact(
-                        RepositoryUtils.toArtifact(getProject().getArtifact()),
-                        coordinates,
-                        null,
-                        getProject().getRemoteProjectRepositories());
+        return new ArrayList<>(result.values());
+    }
+
+    private List<org.eclipse.aether.graph.Dependency> 
managedDependencies(ArtifactTypeRegistry artifactTypeRegistry) {
+        return ofNullable(getProject().getDependencyManagement())
+                .map(DependencyManagement::getDependencies)
+                .map(list -> list.stream()
+                        .map(d -> RepositoryUtils.toDependency(d, 
artifactTypeRegistry))
+                        .collect(Collectors.toList()))
+                .orElse(null);
     }
 
     /**
diff --git 
a/src/main/java/org/apache/maven/plugins/dependency/utils/AnnotationProcessorPaths.java
 
b/src/main/java/org/apache/maven/plugins/dependency/utils/AnnotationProcessorPaths.java
index 7e0851cc..19233818 100644
--- 
a/src/main/java/org/apache/maven/plugins/dependency/utils/AnnotationProcessorPaths.java
+++ 
b/src/main/java/org/apache/maven/plugins/dependency/utils/AnnotationProcessorPaths.java
@@ -20,10 +20,14 @@ package org.apache.maven.plugins.dependency.utils;
 
 import java.util.ArrayList;
 import java.util.Collection;
+import java.util.Collections;
 import java.util.LinkedHashMap;
+import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Objects;
+import java.util.Set;
+import java.util.TreeSet;
 import java.util.function.Consumer;
 
 import org.apache.maven.model.Dependency;
@@ -37,6 +41,11 @@ import org.codehaus.plexus.util.xml.Xpp3Dom;
  * Reads the {@code annotationProcessorPaths} of the {@code 
maven-compiler-plugin} from the configuration of build
  * plugins. Maven does not resolve these artifacts as plugin dependencies, so 
they have to be found in the
  * configuration.
+ *
+ * <p>Each configuration (the plugin level one and one per execution) yields 
its own {@link Group}, because the
+ * compiler plugin resolves the paths of one configuration together. 
Exclusions are read as {@code groupId} and
+ * {@code artifactId} only; a {@code classifier} or {@code extension} in an 
exclusion is ignored, so the exclusion
+ * matches every classifier and extension.
  */
 public final class AnnotationProcessorPaths {
 
@@ -46,87 +55,151 @@ public final class AnnotationProcessorPaths {
 
     private static final String PARAMETER = "annotationProcessorPaths";
 
+    private static final String USE_DEP_MGMT_PARAMETER = 
"annotationProcessorPathsUseDepMgmt";
+
     private AnnotationProcessorPaths() {}
 
     /**
-     * Collects the annotation processor paths configured for the {@code 
maven-compiler-plugin}, both in the plugin
-     * configuration and in the configuration of each of its executions.
+     * The processor paths of one configuration of the compiler plugin.
+     */
+    public static final class Group {
+
+        private final List<Dependency> paths;
+
+        private final boolean useDependencyManagement;
+
+        private final String key;
+
+        Group(List<Dependency> paths, boolean useDependencyManagement) {
+            this.paths = Collections.unmodifiableList(paths);
+            this.useDependencyManagement = useDependencyManagement;
+            StringBuilder sb = new 
StringBuilder().append(useDependencyManagement);
+            for (Dependency d : paths) {
+                sb.append('|').append(key(d));
+            }
+            this.key = sb.toString();
+        }
+
+        /**
+         * @return the paths as compile scope dependencies, without 
duplicates, in configuration order
+         */
+        public List<Dependency> getPaths() {
+            return paths;
+        }
+
+        /**
+         * @return the value of {@code annotationProcessorPathsUseDepMgmt}: 
whether the dependency management of the
+         *         project applies to the transitive dependencies of the paths
+         */
+        public boolean isUseDependencyManagement() {
+            return useDependencyManagement;
+        }
+
+        @Override
+        public boolean equals(Object o) {
+            return o instanceof Group && ((Group) o).key.equals(key);
+        }
+
+        @Override
+        public int hashCode() {
+            return key.hashCode();
+        }
+    }
+
+    /**
+     * Collects the annotation processor paths configured for the {@code 
maven-compiler-plugin}, one group for the
+     * plugin configuration and one for each of its executions that configures 
paths. Identical groups are returned
+     * once.
      *
      * @param plugins the build plugins of the project, from the effective 
model
      * @param dependencyManagement the dependency management of the project, 
used for paths without a version; may be
      *                             {@code null}
      * @param warn receives a message for each path that is skipped
-     * @return the paths as compile scope dependencies, without duplicates, in 
configuration order
+     * @return the groups, in configuration order
      */
-    public static List<Dependency> collect(
+    public static List<Group> collect(
             Collection<Plugin> plugins, DependencyManagement 
dependencyManagement, Consumer<String> warn) {
-        Map<String, Dependency> result = new LinkedHashMap<>();
+        Set<Group> result = new LinkedHashSet<>();
         for (Plugin plugin : plugins) {
             if (!COMPILER_PLUGIN_GROUP_ID.equals(plugin.getGroupId())
                     || 
!COMPILER_PLUGIN_ARTIFACT_ID.equals(plugin.getArtifactId())) {
                 continue;
             }
-            List<Object> configurations = new ArrayList<>();
-            configurations.add(plugin.getConfiguration());
+            Object pluginConfiguration = plugin.getConfiguration();
+            addGroup(result, pluginConfiguration, pluginConfiguration, 
dependencyManagement, warn);
             for (PluginExecution execution : plugin.getExecutions()) {
-                configurations.add(execution.getConfiguration());
-            }
-            for (Object configuration : configurations) {
-                for (Dependency dependency : parse(configuration, 
dependencyManagement, warn)) {
-                    result.putIfAbsent(key(dependency), dependency);
-                }
+                addGroup(result, execution.getConfiguration(), 
pluginConfiguration, dependencyManagement, warn);
             }
         }
-        return new ArrayList<>(result.values());
+        return new ArrayList<>(result);
     }
 
-    private static List<Dependency> parse(
-            Object configuration, DependencyManagement dependencyManagement, 
Consumer<String> warn) {
-        List<Dependency> dependencies = new ArrayList<>();
+    private static void addGroup(
+            Set<Group> result,
+            Object configuration,
+            Object pluginConfiguration,
+            DependencyManagement dependencyManagement,
+            Consumer<String> warn) {
         if (!(configuration instanceof Xpp3Dom)) {
-            return dependencies;
+            return;
         }
         Xpp3Dom paths = ((Xpp3Dom) configuration).getChild(PARAMETER);
         if (paths == null) {
-            return dependencies;
+            return;
         }
+        Map<String, Dependency> dependencies = new LinkedHashMap<>();
         for (Xpp3Dom path : paths.getChildren()) {
-            Dependency dependency = new Dependency();
-            dependency.setGroupId(value(path, "groupId"));
-            dependency.setArtifactId(value(path, "artifactId"));
-            dependency.setVersion(value(path, "version"));
-            String type = value(path, "type");
-            dependency.setType(type == null ? "jar" : type);
-            dependency.setClassifier(value(path, "classifier"));
-            dependency.setScope("compile");
-
-            if (dependency.getGroupId() == null || dependency.getArtifactId() 
== null) {
-                warn.accept("Skipping annotation processor path without 
groupId or artifactId: " + path);
-                continue;
+            Dependency dependency = parse(path, dependencyManagement, warn);
+            if (dependency != null) {
+                dependencies.putIfAbsent(key(dependency), dependency);
             }
+        }
+        if (dependencies.isEmpty()) {
+            return;
+        }
+        // an execution that does not set the flag inherits the one of the 
plugin configuration
+        String flag = value((Xpp3Dom) configuration, USE_DEP_MGMT_PARAMETER);
+        if (flag == null && pluginConfiguration instanceof Xpp3Dom) {
+            flag = value((Xpp3Dom) pluginConfiguration, 
USE_DEP_MGMT_PARAMETER);
+        }
+        result.add(new Group(new ArrayList<>(dependencies.values()), 
Boolean.parseBoolean(flag)));
+    }
+
+    private static Dependency parse(Xpp3Dom path, DependencyManagement 
dependencyManagement, Consumer<String> warn) {
+        Dependency dependency = new Dependency();
+        dependency.setGroupId(value(path, "groupId"));
+        dependency.setArtifactId(value(path, "artifactId"));
+        dependency.setVersion(value(path, "version"));
+        String type = value(path, "type");
+        dependency.setType(type == null ? "jar" : type);
+        dependency.setClassifier(value(path, "classifier"));
+        dependency.setScope("compile");
+
+        if (dependency.getGroupId() == null || dependency.getArtifactId() == 
null) {
+            warn.accept("Skipping annotation processor path without groupId or 
artifactId: " + path);
+            return null;
+        }
+        if (dependency.getVersion() == null) {
+            dependency.setVersion(managedVersion(dependency, 
dependencyManagement));
             if (dependency.getVersion() == null) {
-                dependency.setVersion(managedVersion(dependency, 
dependencyManagement));
-                if (dependency.getVersion() == null) {
-                    warn.accept("Skipping annotation processor path " + 
dependency.getGroupId() + ":"
-                            + dependency.getArtifactId()
-                            + ": it has no version and none is managed in 
dependencyManagement");
-                    continue;
-                }
+                warn.accept("Skipping annotation processor path " + 
dependency.getGroupId() + ":"
+                        + dependency.getArtifactId()
+                        + ": it has no version and none is managed in 
dependencyManagement; compilation will fail");
+                return null;
             }
-            Xpp3Dom exclusions = path.getChild("exclusions");
-            if (exclusions != null) {
-                for (Xpp3Dom exclusionNode : 
exclusions.getChildren("exclusion")) {
-                    Exclusion exclusion = new Exclusion();
-                    exclusion.setGroupId(value(exclusionNode, "groupId"));
-                    exclusion.setArtifactId(value(exclusionNode, 
"artifactId"));
-                    if (exclusion.getGroupId() != null && 
exclusion.getArtifactId() != null) {
-                        dependency.addExclusion(exclusion);
-                    }
+        }
+        Xpp3Dom exclusions = path.getChild("exclusions");
+        if (exclusions != null) {
+            for (Xpp3Dom exclusionNode : exclusions.getChildren("exclusion")) {
+                Exclusion exclusion = new Exclusion();
+                exclusion.setGroupId(value(exclusionNode, "groupId"));
+                exclusion.setArtifactId(value(exclusionNode, "artifactId"));
+                if (exclusion.getGroupId() != null && 
exclusion.getArtifactId() != null) {
+                    dependency.addExclusion(exclusion);
                 }
             }
-            dependencies.add(dependency);
         }
-        return dependencies;
+        return dependency;
     }
 
     private static String managedVersion(Dependency dependency, 
DependencyManagement dependencyManagement) {
@@ -155,7 +228,12 @@ public final class AnnotationProcessorPaths {
         return value == null || value.isEmpty() ? null : value;
     }
 
+    /** Identity of a path, including its exclusions. */
     private static String key(Dependency dependency) {
-        return dependency.getManagementKey() + ":" + dependency.getVersion();
+        Set<String> exclusions = new TreeSet<>();
+        for (Exclusion e : dependency.getExclusions()) {
+            exclusions.add(e.getGroupId() + ":" + e.getArtifactId());
+        }
+        return dependency.getManagementKey() + ":" + dependency.getVersion() + 
exclusions;
     }
 }
diff --git a/src/site/markdown/usage.md.vm b/src/site/markdown/usage.md.vm
index 4a91f049..246e6a0d 100644
--- a/src/site/markdown/usage.md.vm
+++ b/src/site/markdown/usage.md.vm
@@ -387,7 +387,7 @@ This is the same as the resolve goal except it resolves 
plugins and optionally t
 `dependency:go-offline`
 -----------------------
 
-This goal is exactly the same as calling `mvn dependency:resolve 
dependency:resolve-plugins`.
+This goal resolves the same artifacts as calling `mvn dependency:resolve 
dependency:resolve-plugins`. In addition, it resolves the artifacts listed in 
the `annotationProcessorPaths` of the `maven-compiler-plugin`, which Maven 3 
resolves only when it compiles. The paths are read from the plugin 
configuration and from each execution, and their transitive dependencies are 
resolved too (with the project's `dependencyManagement` when 
`annotationProcessorPathsUseDepMgmt` is `true`). The scope  [...]
 
 `dependency:purge-local-repository`
 -----------------------------------
diff --git 
a/src/test/java/org/apache/maven/plugins/dependency/utils/AnnotationProcessorPathsTest.java
 
b/src/test/java/org/apache/maven/plugins/dependency/utils/AnnotationProcessorPathsTest.java
index 0b186cf0..7c6b7eb9 100644
--- 
a/src/test/java/org/apache/maven/plugins/dependency/utils/AnnotationProcessorPathsTest.java
+++ 
b/src/test/java/org/apache/maven/plugins/dependency/utils/AnnotationProcessorPathsTest.java
@@ -31,6 +31,7 @@ import org.codehaus.plexus.util.xml.Xpp3DomBuilder;
 import org.junit.jupiter.api.Test;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 
 class AnnotationProcessorPathsTest {
@@ -68,12 +69,18 @@ class AnnotationProcessorPathsTest {
                 + (version == null ? "" : "<version>" + version + 
"</version>") + extra + "</path>";
     }
 
-    private List<Dependency> collect(DependencyManagement management, 
Plugin... plugins) {
+    private List<AnnotationProcessorPaths.Group> groups(DependencyManagement 
management, Plugin... plugins) {
         List<Plugin> list = new ArrayList<>();
         Collections.addAll(list, plugins);
         return AnnotationProcessorPaths.collect(list, management, 
warnings::add);
     }
 
+    private List<Dependency> collect(DependencyManagement management, 
Plugin... plugins) {
+        List<Dependency> result = new ArrayList<>();
+        groups(management, plugins).forEach(g -> result.addAll(g.getPaths()));
+        return result;
+    }
+
     @Test
     void readsPluginLevelConfiguration() throws Exception {
         List<Dependency> result = collect(null, compiler(paths(path("g", "a", 
"1.0"), path("g", "b", "2.0"))));
@@ -88,18 +95,52 @@ class AnnotationProcessorPathsTest {
     }
 
     @Test
-    void readsExecutionConfigurationAndDeduplicates() throws Exception {
-        List<Dependency> result = collect(
+    void yieldsOneGroupPerConfiguration() throws Exception {
+        List<AnnotationProcessorPaths.Group> groups = groups(
                 null,
                 compiler(
                         paths(path("g", "a", "1.0")),
                         paths(path("g", "a", "1.0"), path("g", "c", "3.0")),
-                        paths(path("g", "a", "1.1"))));
+                        paths(path("g", "a", "1.1")),
+                        paths(path("g", "a", "1.0")),
+                        "<configuration/>"));
+
+        assertEquals(3, groups.size());
+        assertEquals(1, groups.get(0).getPaths().size());
+        assertEquals(2, groups.get(1).getPaths().size());
+        assertEquals("1.1", groups.get(2).getPaths().get(0).getVersion());
+    }
+
+    @Test
+    void doesNotDeduplicatePathsDifferingInExclusions() throws Exception {
+        String exclusion =
+                
"<exclusions><exclusion><groupId>x</groupId><artifactId>y</artifactId></exclusion></exclusions>";
 
-        assertEquals(3, result.size());
-        assertEquals("1.0", result.get(0).getVersion());
-        assertEquals("c", result.get(1).getArtifactId());
-        assertEquals("1.1", result.get(2).getVersion());
+        List<Dependency> result = collect(
+                null, compiler(paths(path("g", "a", "1.0"), path("g", "a", 
"1.0", exclusion), path("g", "a", "1.0"))));
+
+        assertEquals(2, result.size());
+        assertTrue(result.get(0).getExclusions().isEmpty());
+        assertEquals(1, result.get(1).getExclusions().size());
+    }
+
+    @Test
+    void readsUseDepMgmtFromTheConfiguration() throws Exception {
+        String on = 
"<annotationProcessorPathsUseDepMgmt>true</annotationProcessorPathsUseDepMgmt>";
+        String off = 
"<annotationProcessorPathsUseDepMgmt>false</annotationProcessorPathsUseDepMgmt>";
+        String pathsOnly = paths(path("g", "a", "1.0"));
+
+        List<AnnotationProcessorPaths.Group> groups = groups(
+                null,
+                compiler(
+                        pathsOnly.replace("<configuration>", "<configuration>" 
+ on),
+                        // inherits the plugin level flag, so it equals the 
plugin level group
+                        pathsOnly,
+                        pathsOnly.replace("<configuration>", "<configuration>" 
+ off)));
+
+        assertEquals(2, groups.size());
+        assertTrue(groups.get(0).isUseDependencyManagement());
+        assertFalse(groups.get(1).isUseDependencyManagement());
     }
 
     @Test
@@ -144,6 +185,7 @@ class AnnotationProcessorPathsTest {
         assertEquals("b", result.get(0).getArtifactId());
         assertEquals(1, warnings.size());
         assertTrue(warnings.get(0).contains("g:a"));
+        assertTrue(warnings.get(0).contains("compilation will fail"));
     }
 
     @Test

Reply via email to