This is an automated email from the ASF dual-hosted git repository.
gnodet pushed a commit to branch maven-4.0.x
in repository https://gitbox.apache.org/repos/asf/maven.git
The following commit(s) were added to refs/heads/maven-4.0.x by this push:
new e58122fe31 [Backport maven-4.0.x] #14094: Keep system-scoped
dependencies on compile and test class paths (#14108)
e58122fe31 is described below
commit e58122fe317b10ba67a78a2723fd7577b2a8abbd
Author: Guillaume Nodet <[email protected]>
AuthorDate: Mon Nov 23 17:40:19 2026 +0100
[Backport maven-4.0.x] #14094: Keep system-scoped dependencies on compile
and test class paths (#14108)
- Add DependencyScope.SYSTEM to MAIN_COMPILE, TEST_COMPILE, and
TEST_RUNTIME path scopes
- MAIN_RUNTIME still excludes system scope (intentional: matches
main-runtime semantics)
- Adds
DefaultDependencyResolverTest.flattenKeepsSystemScopeOnCompileAndTestPaths
(adapted for maven-4.0.x: strips tests for applyDependencyManagement,
which is a
master-only addition not present in this branch)
Cherry-picked from 9bf1ccaf7f9aa4ab78f27b364273d589d4c25d11
Co-authored-by: dev_Hakaze <[email protected]>
---
.../main/java/org/apache/maven/api/PathScope.java | 9 +-
.../maven/impl/DefaultDependencyResolverTest.java | 107 +++++++++++++++++++++
2 files changed, 113 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 bd8a6f1bf5..31f61cd335 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
@@ -58,7 +58,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);
@@ -69,7 +70,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",
@@ -78,5 +80,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
new file mode 100644
index 0000000000..94728e633b
--- /dev/null
+++
b/impl/maven-impl/src/test/java/org/apache/maven/impl/DefaultDependencyResolverTest.java
@@ -0,0 +1,107 @@
+/*
+ * 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.impl;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.maven.api.Node;
+import org.apache.maven.api.PathScope;
+import org.eclipse.aether.RepositorySystem;
+import org.eclipse.aether.RepositorySystemSession;
+import org.eclipse.aether.artifact.DefaultArtifact;
+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.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+class DefaultDependencyResolverTest {
+
+ @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));
+ }
+}