You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by sl...@apache.org on 2026/10/06 19:06:08 UTC
(maven-dependency-plugin) branch master updated: Ignore scopes outside the Java scopes in the verbose scope selector
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
The following commit(s) were added to refs/heads/master by this push:
new d1b75717 Ignore scopes outside the Java scopes in the verbose scope selector
d1b75717 is described below
commit d1b75717809e89317b25f6a66785eadece8bbb9c
Author: Sylwester Lachiewicz <sl...@apache.org>
AuthorDate: Tue Oct 6 00:04:09 2026 +0200
Ignore scopes outside the Java scopes in the verbose scope selector
indexOf returns -1 for system, which ranked it widest: a losing system
dependency was reported as "scope not updated to system", and a winning
one hid the wider scope it did not take. Same defect as
apache/maven-dependency-tree#136, carried over by MDEP-969.
---
.../dependency/tree/VerboseJavaScopeSelector.java | 1 +
.../tree/VerboseJavaScopeSelectorTest.java | 68 ++++++++++++++++++++++
2 files changed, 69 insertions(+)
diff --git a/src/main/java/org/apache/maven/plugins/dependency/tree/VerboseJavaScopeSelector.java b/src/main/java/org/apache/maven/plugins/dependency/tree/VerboseJavaScopeSelector.java
index 566ceff9..54240b1f 100644
--- a/src/main/java/org/apache/maven/plugins/dependency/tree/VerboseJavaScopeSelector.java
+++ b/src/main/java/org/apache/maven/plugins/dependency/tree/VerboseJavaScopeSelector.java
@@ -45,6 +45,7 @@ class VerboseJavaScopeSelector extends ScopeSelector {
context.getItems().stream()
.flatMap(i -> i.getScopes().stream())
.distinct()
+ .filter(ORDERED_SCOPES::contains)
.max(Comparator.comparingInt((String s) -> ORDERED_SCOPES.indexOf(s))
.reversed())
.filter(s -> !s.equals(context.getScope()))
diff --git a/src/test/java/org/apache/maven/plugins/dependency/tree/VerboseJavaScopeSelectorTest.java b/src/test/java/org/apache/maven/plugins/dependency/tree/VerboseJavaScopeSelectorTest.java
new file mode 100644
index 00000000..260cd235
--- /dev/null
+++ b/src/test/java/org/apache/maven/plugins/dependency/tree/VerboseJavaScopeSelectorTest.java
@@ -0,0 +1,68 @@
+/*
+ * 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.tree;
+
+import java.util.Arrays;
+import java.util.Collections;
+
+import org.eclipse.aether.artifact.DefaultArtifact;
+import org.eclipse.aether.graph.DefaultDependencyNode;
+import org.eclipse.aether.graph.Dependency;
+import org.eclipse.aether.graph.DependencyNode;
+import org.eclipse.aether.util.graph.transformer.ConflictResolver.ConflictContext;
+import org.eclipse.aether.util.graph.transformer.ConflictResolver.ConflictItem;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
+
+class VerboseJavaScopeSelectorTest {
+
+ private static DependencyNode node(String scope) {
+ return new DefaultDependencyNode(new Dependency(new DefaultArtifact("g:a:1"), scope));
+ }
+
+ private static ConflictContext select(String winnerScope, String loserScope) throws Exception {
+ DependencyNode winnerNode = node(winnerScope);
+ ConflictItem winner = new ConflictItem(null, winnerNode, 1, ConflictItem.OPTIONAL_FALSE, winnerScope);
+ ConflictItem loser = new ConflictItem(null, node(loserScope), 2, ConflictItem.OPTIONAL_FALSE, loserScope);
+ ConflictContext context =
+ new ConflictContext(node(""), "g:a", Collections.emptyMap(), Arrays.asList(winner, loser));
+ context.setWinner(winner);
+
+ new VerboseJavaScopeSelector().selectScope(context);
+ return context;
+ }
+
+ @Test
+ void reportsWiderScopeThatWasNotApplied() throws Exception {
+ ConflictContext context = select("system", "compile");
+
+ assertEquals("system", context.getScope());
+ assertEquals("compile", context.getWinner().getNode().getData().get(VerboseJavaScopeSelector.REDUCED_SCOPE));
+ }
+
+ @Test
+ void ignoresScopesOutsideTheJavaScopes() throws Exception {
+ ConflictContext context = select("compile", "system");
+
+ assertEquals("compile", context.getScope());
+ assertNull(context.getWinner().getNode().getData().get(VerboseJavaScopeSelector.REDUCED_SCOPE));
+ }
+}