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

gnodet pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven.git


The following commit(s) were added to refs/heads/master by this push:
     new 9bf1ccaf7f Keep system scope on compile and test path scopes (#14094)
9bf1ccaf7f is described below

commit 9bf1ccaf7f9aa4ab78f27b364273d589d4c25d11
Author: dev_Hakaze <[email protected]>
AuthorDate: Mon Nov 23 16:18:15 2026 +0700

    Keep system scope on compile and test path scopes (#14094)
    
    DependencyResolver keeps a flattened node only when its scope is in the
    path scope. main-compile, test-compile, and test-runtime already include
    system in the matching resolution scopes, but those path scopes omitted
    it, so a system-scoped jar was collected and then dropped. main-runtime
    still excludes system.
    
    Fixes #14004
    
    Co-authored-by: arimu1 <[email protected]>
---
 .../main/java/org/apache/maven/api/PathScope.java  |  9 ++-
 .../maven/impl/DefaultDependencyResolverTest.java  | 69 ++++++++++++++++++++++
 2 files changed, 75 insertions(+), 3 deletions(-)

diff --git 
a/api/maven-api-core/src/main/java/org/apache/maven/api/PathScope.java 
b/api/maven-api-core/src/main/java/org/apache/maven/api/PathScope.java
index 34c9158cc6..925782fe6a 100644
--- a/api/maven-api-core/src/main/java/org/apache/maven/api/PathScope.java
+++ b/api/maven-api-core/src/main/java/org/apache/maven/api/PathScope.java
@@ -68,7 +68,8 @@ public interface PathScope extends ExtensibleEnum {
             ProjectScope.MAIN,
             DependencyScope.COMPILE_ONLY,
             DependencyScope.COMPILE,
-            DependencyScope.PROVIDED);
+            DependencyScope.PROVIDED,
+            DependencyScope.SYSTEM);
 
     PathScope MAIN_RUNTIME =
             pathScope("main-runtime", ProjectScope.MAIN, 
DependencyScope.COMPILE, DependencyScope.RUNTIME);
@@ -79,7 +80,8 @@ public interface PathScope extends ExtensibleEnum {
             DependencyScope.COMPILE,
             DependencyScope.PROVIDED,
             DependencyScope.TEST_ONLY,
-            DependencyScope.TEST);
+            DependencyScope.TEST,
+            DependencyScope.SYSTEM);
 
     PathScope TEST_RUNTIME = pathScope(
             "test-runtime",
@@ -88,5 +90,6 @@ public interface PathScope extends ExtensibleEnum {
             DependencyScope.RUNTIME,
             DependencyScope.PROVIDED,
             DependencyScope.TEST,
-            DependencyScope.TEST_RUNTIME);
+            DependencyScope.TEST_RUNTIME,
+            DependencyScope.SYSTEM);
 }
diff --git 
a/impl/maven-impl/src/test/java/org/apache/maven/impl/DefaultDependencyResolverTest.java
 
b/impl/maven-impl/src/test/java/org/apache/maven/impl/DefaultDependencyResolverTest.java
index e16aa5d4de..666e9c7a17 100644
--- 
a/impl/maven-impl/src/test/java/org/apache/maven/impl/DefaultDependencyResolverTest.java
+++ 
b/impl/maven-impl/src/test/java/org/apache/maven/impl/DefaultDependencyResolverTest.java
@@ -18,6 +18,7 @@
  */
 package org.apache.maven.impl;
 
+import java.util.ArrayList;
 import java.util.List;
 import java.util.Optional;
 import java.util.concurrent.atomic.AtomicReference;
@@ -25,6 +26,7 @@
 
 import org.apache.maven.api.DependencyCoordinates;
 import org.apache.maven.api.Node;
+import org.apache.maven.api.PathScope;
 import org.apache.maven.api.Project;
 import org.apache.maven.api.services.DependencyResolverRequest;
 import org.apache.maven.api.services.DependencyResolverResult;
@@ -36,6 +38,8 @@
 import org.eclipse.aether.collection.CollectResult;
 import org.eclipse.aether.graph.DefaultDependencyNode;
 import org.eclipse.aether.graph.Dependency;
+import org.eclipse.aether.graph.DependencyFilter;
+import org.eclipse.aether.graph.DependencyNode;
 import org.eclipse.aether.graph.Exclusion;
 import org.junit.jupiter.api.Test;
 import org.mockito.ArgumentCaptor;
@@ -218,6 +222,71 @@ void 
appliesDependencyManagementOnlyToMatchingDependencies() {
         assertSame(unmatched, result.get(1));
     }
 
+    @Test
+    void flattenKeepsSystemScopeOnCompileAndTestPaths() throws Exception {
+        // main-runtime deliberately excludes system; main-runtimePlusSystem 
is a separate resolution scope.
+        InternalSession session = mock(InternalSession.class);
+        RepositorySystem repositorySystem = mock(RepositorySystem.class);
+        RepositorySystemSession repositorySession = 
mock(RepositorySystemSession.class);
+        when(session.getRepositorySystem()).thenReturn(repositorySystem);
+        when(session.getSession()).thenReturn(repositorySession);
+
+        DependencyNode root = scopedNode("root", "compile");
+        List<DependencyNode> children = List.of(
+                scopedNode("syslib", "system"),
+                scopedNode("compilelib", "compile"),
+                scopedNode("runtimelib", "runtime"));
+        Node rootNode = new DefaultNode(session, root, false);
+        when(repositorySystem.flattenDependencyNodes(eq(repositorySession), 
eq(root), any(DependencyFilter.class)))
+                .thenAnswer(invocation -> {
+                    DependencyFilter filter = invocation.getArgument(2);
+                    List<DependencyNode> kept = new ArrayList<>();
+                    for (DependencyNode child : children) {
+                        if (filter.accept(child, List.of(root))) {
+                            kept.add(child);
+                        }
+                    }
+                    return kept;
+                });
+        List<String> scopes = new ArrayList<>();
+        when(session.getNode(any(DependencyNode.class))).thenAnswer(invocation 
-> {
+            DependencyNode dependencyNode = invocation.getArgument(0);
+            scopes.add(dependencyNode.getDependency().getScope());
+            return mock(Node.class);
+        });
+
+        DefaultDependencyResolver resolver = new DefaultDependencyResolver();
+        assertEquals(
+                List.of("system", "compile"),
+                flattenedScopes(resolver, session, rootNode, 
PathScope.MAIN_COMPILE, scopes));
+        assertEquals(
+                List.of("system", "compile"),
+                flattenedScopes(resolver, session, rootNode, 
PathScope.TEST_COMPILE, scopes));
+        assertEquals(
+                List.of("system", "compile", "runtime"),
+                flattenedScopes(resolver, session, rootNode, 
PathScope.TEST_RUNTIME, scopes));
+        assertEquals(
+                List.of("compile", "runtime"),
+                flattenedScopes(resolver, session, rootNode, 
PathScope.MAIN_RUNTIME, scopes));
+    }
+
+    private static List<String> flattenedScopes(
+            DefaultDependencyResolver resolver,
+            InternalSession session,
+            Node rootNode,
+            PathScope pathScope,
+            List<String> scopes)
+            throws Exception {
+        scopes.clear();
+        resolver.flatten(session, rootNode, pathScope);
+        return List.copyOf(scopes);
+    }
+
+    private static DependencyNode scopedNode(String artifactId, String scope) {
+        return new DefaultDependencyNode(
+                new Dependency(new DefaultArtifact("org.example:" + artifactId 
+ ":jar:1"), scope));
+    }
+
     private static void trackTrace(InternalSession session, RequestTrace 
initial) {
         AtomicReference<RequestTrace> current = new AtomicReference<>(initial);
         when(session.getCurrentTrace()).thenAnswer(invocation -> 
current.get());

Reply via email to