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 b413e396fc19ca2b98f7a25da7ed1da2dbe2e76e
Author: Pericart Vincent[ PERICARTVINCENT ] <[email protected]>
AuthorDate: Wed Oct 21 10:30:04 2026 +0900

    Exclude transitive reactor dependencies in go-offline
    
    Apply a graph-level reactor filter during artifact resolution so reactor
    modules reached through external dependencies are excluded as well.
    
    Keep the dependency-only collection request used by go-offline. The existing
    five-argument resolver overload resolves the root and reads its descriptor,
    which bypasses the filtered dependency list and attempts to download the
    unbuilt project artifact when excludeReactor=false. Expose the shared
    request-based resolver helper without changing the existing overloads.
    
    Include graph-filter unit tests and an excludeReactor=false invocation of
    the existing go-offline integration test.
---
 src/it/projects/go-offline/invoker.properties      |  3 +-
 ...xcludeReactorProjectsGraphDependencyFilter.java | 66 ++++++++++++++++
 .../dependency/resolvers/GoOfflineMojo.java        | 17 ++--
 .../plugins/dependency/utils/ResolverUtil.java     | 11 ++-
 ...deReactorProjectsGraphDependencyFilterTest.java | 92 ++++++++++++++++++++++
 5 files changed, 181 insertions(+), 8 deletions(-)

diff --git a/src/it/projects/go-offline/invoker.properties 
b/src/it/projects/go-offline/invoker.properties
index e5961219..279f3ae5 100644
--- a/src/it/projects/go-offline/invoker.properties
+++ b/src/it/projects/go-offline/invoker.properties
@@ -15,4 +15,5 @@
 # specific language governing permissions and limitations
 # under the License.
 
-invoker.goals = 
${project.groupId}:${project.artifactId}:${project.version}:go-offline
+invoker.goals.1 = 
${project.groupId}:${project.artifactId}:${project.version}:go-offline
+invoker.goals.2 = 
${project.groupId}:${project.artifactId}:${project.version}:go-offline 
-DexcludeReactor=false
diff --git 
a/src/main/java/org/apache/maven/plugins/dependency/resolvers/ExcludeReactorProjectsGraphDependencyFilter.java
 
b/src/main/java/org/apache/maven/plugins/dependency/resolvers/ExcludeReactorProjectsGraphDependencyFilter.java
new file mode 100644
index 00000000..67740e75
--- /dev/null
+++ 
b/src/main/java/org/apache/maven/plugins/dependency/resolvers/ExcludeReactorProjectsGraphDependencyFilter.java
@@ -0,0 +1,66 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.maven.plugins.dependency.resolvers;
+
+import java.util.List;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+import org.apache.maven.artifact.ArtifactUtils;
+import org.apache.maven.project.MavenProject;
+import org.eclipse.aether.artifact.Artifact;
+import org.eclipse.aether.graph.DependencyFilter;
+import org.eclipse.aether.graph.DependencyNode;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Aether {@link DependencyFilter} implementation that excludes artifacts 
found in the Reactor, applied to the whole
+ * resolved dependency graph so transitive nodes pointing at reactor modules 
are skipped during artifact resolution.
+ */
+public class ExcludeReactorProjectsGraphDependencyFilter implements 
DependencyFilter {
+
+    private final Logger log = 
LoggerFactory.getLogger(ExcludeReactorProjectsGraphDependencyFilter.class);
+    private final Set<String> reactorArtifactKeys;
+
+    public ExcludeReactorProjectsGraphDependencyFilter(final 
List<MavenProject> reactorProjects) {
+        this.reactorArtifactKeys = reactorProjects.stream()
+                .map(project -> ArtifactUtils.key(project.getArtifact()))
+                .collect(Collectors.toSet());
+    }
+
+    @Override
+    public boolean accept(DependencyNode node, List<DependencyNode> parents) {
+        if (node == null) {
+            return true;
+        }
+        Artifact artifact = node.getArtifact();
+        if (artifact == null) {
+            return true;
+        }
+        String key = ArtifactUtils.key(artifact.getGroupId(), 
artifact.getArtifactId(), artifact.getVersion());
+        if (reactorArtifactKeys.contains(key)) {
+            if (log.isDebugEnabled()) {
+                log.debug("Skipped transitive dependency {} because it is 
present in the reactor", key);
+            }
+            return false;
+        }
+        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 44725a49..7774137e 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
@@ -60,6 +60,8 @@ import 
org.apache.maven.shared.artifact.filter.collection.FilterArtifacts;
 import org.apache.maven.shared.artifact.filter.collection.ScopeFilter;
 import org.apache.maven.shared.artifact.filter.collection.TypeFilter;
 import org.eclipse.aether.artifact.ArtifactTypeRegistry;
+import org.eclipse.aether.collection.CollectRequest;
+import org.eclipse.aether.graph.DependencyFilter;
 import org.eclipse.aether.resolution.ArtifactDescriptorException;
 import org.eclipse.aether.resolution.ArtifactResolutionException;
 import org.eclipse.aether.resolution.ArtifactResult;
@@ -194,12 +196,15 @@ public class GoOfflineMojo extends 
AbstractDependencyFilterMojo {
 
         List<org.eclipse.aether.graph.Dependency> managedDependencies = 
managedDependencies(artifactTypeRegistry);
 
-        return getResolverUtil()
-                .resolveDependenciesForArtifact(
-                        RepositoryUtils.toArtifact(getProject().getArtifact()),
-                        dependableCoordinates,
-                        managedDependencies,
-                        getProject().getRemoteProjectRepositories());
+        DependencyFilter graphReactorFilter = null;
+        if (this.excludeReactor) {
+            graphReactorFilter = new 
ExcludeReactorProjectsGraphDependencyFilter(session.getProjects());
+        }
+
+        CollectRequest collectRequest = new CollectRequest(
+                dependableCoordinates, managedDependencies, 
getProject().getRemoteProjectRepositories());
+        
collectRequest.setRootArtifact(RepositoryUtils.toArtifact(getProject().getArtifact()));
+        return getResolverUtil().resolveDependencies(collectRequest, 
graphReactorFilter);
     }
 
     /**
diff --git 
a/src/main/java/org/apache/maven/plugins/dependency/utils/ResolverUtil.java 
b/src/main/java/org/apache/maven/plugins/dependency/utils/ResolverUtil.java
index 56be82f5..e7ced0c6 100644
--- a/src/main/java/org/apache/maven/plugins/dependency/utils/ResolverUtil.java
+++ b/src/main/java/org/apache/maven/plugins/dependency/utils/ResolverUtil.java
@@ -471,7 +471,16 @@ public class ResolverUtil {
         return resolveDependencies(collectRequest, dependencyFilter);
     }
 
-    private List<Artifact> resolveDependencies(CollectRequest collectRequest, 
DependencyFilter dependencyFilter)
+    /**
+     * Resolve the dependencies described by a collection request, applying 
the filter to the dependency graph.
+     *
+     * @param collectRequest the dependencies and root to collect
+     * @param dependencyFilter dependency filter, or {@code null}
+     * @return resolved dependencies
+     * @throws DependencyResolutionException if the dependency tree could not 
be built or any dependency artifact could
+     *                                       not be resolved
+     */
+    public List<Artifact> resolveDependencies(CollectRequest collectRequest, 
DependencyFilter dependencyFilter)
             throws DependencyResolutionException {
         MavenSession session = mavenSessionProvider.get();
         DependencyRequest request = new DependencyRequest(collectRequest, 
dependencyFilter);
diff --git 
a/src/test/java/org/apache/maven/plugins/dependency/resolvers/ExcludeReactorProjectsGraphDependencyFilterTest.java
 
b/src/test/java/org/apache/maven/plugins/dependency/resolvers/ExcludeReactorProjectsGraphDependencyFilterTest.java
new file mode 100644
index 00000000..b686bf98
--- /dev/null
+++ 
b/src/test/java/org/apache/maven/plugins/dependency/resolvers/ExcludeReactorProjectsGraphDependencyFilterTest.java
@@ -0,0 +1,92 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.maven.plugins.dependency.resolvers;
+
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.DefaultArtifact;
+import org.apache.maven.project.MavenProject;
+import org.eclipse.aether.graph.DefaultDependencyNode;
+import org.eclipse.aether.graph.Dependency;
+import org.eclipse.aether.graph.DependencyNode;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.Mock;
+import org.mockito.junit.jupiter.MockitoExtension;
+
+import static java.util.Collections.emptyList;
+import static java.util.Collections.singletonList;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.Mockito.when;
+
+@ExtendWith(MockitoExtension.class)
+class ExcludeReactorProjectsGraphDependencyFilterTest {
+
+    @Mock
+    private MavenProject project;
+
+    @Test
+    void testRejectReactorTransitive() {
+        Artifact reactorArtifact = anArtifact();
+        when(project.getArtifact()).thenReturn(reactorArtifact);
+
+        ExcludeReactorProjectsGraphDependencyFilter filter =
+                new 
ExcludeReactorProjectsGraphDependencyFilter(singletonList(project));
+
+        DependencyNode node =
+                nodeFor(reactorArtifact.getGroupId(), 
reactorArtifact.getArtifactId(), reactorArtifact.getVersion());
+
+        assertFalse(filter.accept(node, emptyList()));
+    }
+
+    @Test
+    void testAcceptNonReactorTransitive() {
+        Artifact reactorArtifact = anArtifact();
+        when(project.getArtifact()).thenReturn(reactorArtifact);
+
+        ExcludeReactorProjectsGraphDependencyFilter filter =
+                new 
ExcludeReactorProjectsGraphDependencyFilter(singletonList(project));
+
+        DependencyNode node = nodeFor("something-else", 
reactorArtifact.getArtifactId(), reactorArtifact.getVersion());
+
+        assertTrue(filter.accept(node, emptyList()));
+    }
+
+    @Test
+    void testAcceptNullArtifact() {
+        Artifact reactorArtifact = anArtifact();
+        when(project.getArtifact()).thenReturn(reactorArtifact);
+
+        ExcludeReactorProjectsGraphDependencyFilter filter =
+                new 
ExcludeReactorProjectsGraphDependencyFilter(singletonList(project));
+
+        assertTrue(filter.accept(new DefaultDependencyNode((Dependency) null), 
emptyList()));
+    }
+
+    private static DependencyNode nodeFor(String groupId, String artifactId, 
String version) {
+        org.eclipse.aether.artifact.Artifact aetherArtifact =
+                new org.eclipse.aether.artifact.DefaultArtifact(groupId, 
artifactId, "jar", version);
+        return new DefaultDependencyNode(new Dependency(aetherArtifact, null));
+    }
+
+    private Artifact anArtifact() {
+        return new DefaultArtifact(
+                "org.apache.maven.plugins", "maven-dependency-plugin-dummy", 
"1.0", null, "jar", "", null);
+    }
+}

Reply via email to