trackoor opened a new issue, #2325: URL: https://github.com/apache/maven-resolver/issues/2325
### Affected version 2.0.25 (also reproduces on master `c7d3f1fa` and 1.9.27; Apache Maven 3.10.1 and 3.9.16) ### Bug description When a retained dependency inside a cycle (`a <-> b`) declares a hard version range on a non-cyclic dependency `c` (`[1.0,2.0)`) that also appears closer to the root (`c:2.0`), `ClassicConflictResolver` (selected by default when `aether.conflictResolver.impl=auto` and in Maven 3.9.x/3.10.x) ignores `b`'s hard version constraint and selects `c:2.0`, violating Maven's [Dependency Version Requirement Specification](https://maven.apache.org/pom.html#dependency-version-requirement-specification). `PathConflictResolver` selects `c:1.0` on the same graph. If the root instead declares a disjoint hard range `c:[2.0,3.0)`, `ClassicConflictResolver` still succeeds with `c:2.0` whereas `PathConflictResolver` throws `UnsolvableVersionConflictException`. Minimal unit test graph for `ConfigurableVersionSelectorTest` / `NearestVersionSelectorTest` (compare `soft-vs-range.txt`): ```text test:root:1 +- test:p:1 | \- test:a:1 | \- test:b:1 (b) | +- test:a:1 | | \- ^b | \- test:c:1[1] \- test:c:2 ``` Running `transform(conflictResolver, root)` and checking `find(root, "c").get(0).getArtifact().getVersion()` returns `"1"` with `PathConflictResolver`, but `"2"` with `ClassicConflictResolver`. Standalone CLI reproduction on Maven 3.10.1 (`maven-resolver 2.0.25`) and Maven 3.9.16 (`maven-resolver 1.9.27`): ```sh write_pom() { dir="repo/example/$1/$2" mkdir -p "$dir" cat > "$dir/$1-$2.pom" <<POM <project xmlns="http://maven.apache.org/POM/4.0.0"> <modelVersion>4.0.0</modelVersion> <groupId>example</groupId> <artifactId>$1</artifactId> <version>$2</version> <dependencies>$3</dependencies> </project> POM touch "$dir/$1-$2.jar" } dep() { printf '<dependency><groupId>example</groupId><artifactId>%s</artifactId><version>%s</version></dependency>' "$1" "$2"; } write_pom p 1.0 "$(dep a 1.0)" write_pom a 1.0 "$(dep b 1.0)" write_pom b 1.0 "$(dep a 1.0)$(dep c '[1.0,2.0)')" write_pom c 1.0 "" write_pom c 2.0 "" cat > repo/example/c/maven-metadata.xml <<'MD' <metadata><groupId>example</groupId><artifactId>c</artifactId><versioning><versions><version>1.0</version><version>2.0</version></versions></versioning></metadata> MD cat > pom.xml <<POM <project xmlns="http://maven.apache.org/POM/4.0.0"> <modelVersion>4.0.0</modelVersion> <groupId>example</groupId> <artifactId>app</artifactId> <version>1.0</version> <repositories> <repository><id>testrepo</id><url>file://$PWD/repo</url></repository> </repositories> <dependencies> <dependency><groupId>example</groupId><artifactId>p</artifactId><version>1.0</version></dependency> <dependency><groupId>example</groupId><artifactId>c</artifactId><version>2.0</version></dependency> </dependencies> </project> POM mvn -q -Dmaven.repo.local="$PWD/m2-classic" dependency:list -Dsort=true -DoutputFile="$PWD/out-classic.txt" && cat "$PWD/out-classic.txt" mvn -q -Dmaven.repo.local="$PWD/m2-path" -Daether.conflictResolver.impl=path dependency:list -Dsort=true -DoutputFile="$PWD/out-path.txt" && cat "$PWD/out-path.txt" ``` Actual output (default `ClassicConflictResolver` on Maven 3.10.1 and 3.9.16): ```text The following files have been resolved: example:a:jar:1.0:compile example:b:jar:1.0:compile example:c:jar:2.0:compile example:p:jar:1.0:compile ``` Expected output (matching `-Daether.conflictResolver.impl=path` on Maven 3.10.1): ```text The following files have been resolved: example:a:jar:1.0:compile example:b:jar:1.0:compile example:c:jar:1.0:compile example:p:jar:1.0:compile ``` In `ConflictIdSorter.topoSortConflictIds`, the cycle-breaking loop selects remaining positive-in-degree conflict IDs by smallest `minDepth`, placing `c` (`minDepth = 1`) ahead of `a` and `b` (`minDepth >= 2`) in `SORTED_CONFLICT_IDS` without adding `c` to `CYCLIC_CONFLICT_IDS`; `ClassicConflictResolver.State.push` then stops at `a` because `a` is not yet in `potentialAncestorIds`, so `b -> c:[1.0,2.0)` is never included in `c`'s conflict items and is later removed as a leftover loser. Credit: https://ucsbplse.github.io/ -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
