[ 
https://issues.apache.org/jira/browse/MRESOLVER-391?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17780453#comment-17780453
 ] 

Tamas Cservenak commented on MRESOLVER-391:
-------------------------------------------

[~perdjesk][~aloubyansky] Thank you both for participating and providing 
reproducers... but, I have a feeling this/these issues is/are NOT resolver 
issues (it seems fine), but a _series of bugs_ in some of plugins... Let me 
explain:

For "raw" Resolver output (to exclude any possible plugin or maven core bug) I 
used MIMA CLI REPL: https://github.com/maveniverse/mima
I took both reproducers, installed them into my local repository and asked MIMA 
for graphs, here are the outputs:

{noformat}
prompt> graph org.example:consumer:1.0-SNAPSHOT
[INFO] Collecting org.example:consumer:1.0-SNAPSHOT
[INFO] 
[INFO] org.example:consumer:jar:1.0-SNAPSHOT
[INFO] \- org.example:lib-a:jar:1.0-SNAPSHOT [compile]
[INFO]    \- com.google.guava:guava:jar:32.1.3-jre [compile]
[INFO]       +- com.google.guava:failureaccess:jar:1.0.1 [compile]
[INFO]       +- 
com.google.guava:listenablefuture:jar:9999.0-empty-to-avoid-conflict-with-guava 
[compile]
[INFO]       +- com.google.code.findbugs:jsr305:jar:3.0.2 [compile]
[INFO]       +- org.checkerframework:checker-qual:jar:3.37.0 [compile]
[INFO]       +- com.google.errorprone:error_prone_annotations:jar:2.21.1 
[compile]
[INFO]       \- com.google.j2objc:j2objc-annotations:jar:2.8 [compile]

prompt> graph org.example:consumer:1.0-SNAPSHOT --excludeScopes=
[INFO] Collecting org.example:consumer:1.0-SNAPSHOT
[INFO] 
[INFO] org.example:consumer:jar:1.0-SNAPSHOT
[INFO] +- org.example:lib-a:jar:1.0-SNAPSHOT [compile]
[INFO] |  \- com.google.guava:guava:jar:32.1.3-jre [compile] (nearer exists)
[INFO] +- com.google.guava:guava:jar:32.1.3-jre [test]
[INFO] |  +- com.google.guava:failureaccess:jar:1.0.1 [test]
[INFO] |  +- 
com.google.guava:listenablefuture:jar:9999.0-empty-to-avoid-conflict-with-guava 
[test]
[INFO] |  +- com.google.code.findbugs:jsr305:jar:3.0.2 [test]
[INFO] |  +- org.checkerframework:checker-qual:jar:3.37.0 [test]
[INFO] |  +- com.google.errorprone:error_prone_annotations:jar:2.21.1 [test]
[INFO] |  |  \- junit:junit:jar:4.13.2 [test]
[INFO] |  |     +- org.hamcrest:hamcrest-core:jar:1.3 [test]
[INFO] |  |     \- org.hamcrest:hamcrest-library:jar:1.3 [test]
[INFO] |  |        \- org.hamcrest:hamcrest-core:jar:1.3 [test] (nearer exists)
[INFO] |  \- com.google.j2objc:j2objc-annotations:jar:2.8 [test]
[INFO] \- org.junit.jupiter:junit-jupiter-engine:jar:5.9.1 [test]
[INFO]    +- org.junit.platform:junit-platform-engine:jar:1.9.1 [test]
[INFO]    |  +- org.opentest4j:opentest4j:jar:1.2.0 [test]
[INFO]    |  +- org.junit.platform:junit-platform-commons:jar:1.9.1 [test]
[INFO]    |  |  \- org.apiguardian:apiguardian-api:jar:1.1.2 [test] (nearer 
exists)
[INFO]    |  \- org.apiguardian:apiguardian-api:jar:1.1.2 [test] (nearer exists)
[INFO]    +- org.junit.jupiter:junit-jupiter-api:jar:5.9.1 [test]
[INFO]    |  +- org.opentest4j:opentest4j:jar:1.2.0 [test] (nearer exists)
[INFO]    |  +- org.junit.platform:junit-platform-commons:jar:1.9.1 [test] 
(nearer exists)
[INFO]    |  \- org.apiguardian:apiguardian-api:jar:1.1.2 [test] (nearer exists)
[INFO]    \- org.apiguardian:apiguardian-api:jar:1.1.2 [test]
{noformat}

and the other reproducer:

{noformat}
prompt> graph org.acme:acme-product-a:jar:1.0.0-SNAPSHOT
[INFO] Collecting org.acme:acme-product-a:jar:1.0.0-SNAPSHOT
[INFO] 
[INFO] org.acme:acme-product-a:jar:1.0.0-SNAPSHOT
[INFO] \- org.acme:acme-lib-b:jar:1.0.0-SNAPSHOT [compile]
[INFO]    \- org.acme:acme-lib-c:jar:1.0.0-SNAPSHOT [compile]

prompt> graph org.acme:acme-product-a:jar:1.0.0-SNAPSHOT --excludeScopes=
[INFO] Collecting org.acme:acme-product-a:jar:1.0.0-SNAPSHOT
[INFO] 
[INFO] org.acme:acme-product-a:jar:1.0.0-SNAPSHOT
[INFO] +- org.acme:acme-lib-d:jar:1.0.0-SNAPSHOT [test]
[INFO] |  \- org.acme:acme-lib-c:jar:2.0.0-SNAPSHOT [compile]
[INFO] \- org.acme:acme-lib-b:jar:1.0.0-SNAPSHOT [compile]
[INFO]    \- org.acme:acme-lib-c:jar:1.0.0-SNAPSHOT [compile] (conflicts with 
2.0.0-SNAPSHOT)
prompt> 
{noformat}

Explanation: by default MIMA {{graph}} displays "runtime" classpath, second 
invocation shows "test" classpath.

Basically, you both want 1st output, but you get 2nd output. But this is not 
due Resolver, but what is Resolver (or Maven core) instructed to do.

For [~perdjesk] seemingly the reason is a bug in m-assembly-p, in short, what 
m-assembly-p does is it resolves the "test" classpath (!) and from that it 
"cherry picks" the "runtime" leaves (collects assembly participants from 
MavenProject that has resolved for test scope, [see 
here|https://github.com/apache/maven-assembly-plugin/blob/master/src/main/java/org/apache/maven/plugins/assembly/mojos/SingleAssemblyMojo.java#L42]).
 This is obviously wrong, as "test" resolved tree is not "bigger runtime" tree, 
it is quite different. When you ask for "runtime" (basically exclude test 
scope). the POM dependencies in "test" scope are IGNORED, hence guava remains 
where it should, as expected.

For [~aloubyansky] issue am still unsure, but m-dependency-p is using archaic 
component m-dependency-graph (that is as evil and old as m-artifact-transfer 
was), but the Mojo there starts as well with "give me test dependencies", 
although it does goes for resolver API (unlike assembly above, that uses 
MavenProject "test" resolved deps by Maven core). I need to check more what 
happens here, but I guess similarly some "scope mixup", given correct MIMA 
output.

In short, it seems we have small but bad bugs spread across the board... 

Just to add a bit more to the story: you _cannot_ have "test" and "runtime" in 
single graph, also as expected. So, basically, resolution does and have to 
differ. The fact that Mojo defines kinda "inverse" of excluded scopes ([see 
here|https://maven.apache.org/plugin-tools/maven-plugin-annotations/apidocs/org/apache/maven/plugins/annotations/ResolutionScope.html]),
 where Mojo expresses "what to include", while resolver works in way "what to 
exclude"... and it also may cause some mixup along devs...

All in all, I see _no issue in resolver_, but rather we need to investigate all 
these spots where wrong expectation (usually the "I need test classpath and 
will cherry pick runtime nodes from it") is seen in code.

> Scope mediation improvements
> ----------------------------
>
>                 Key: MRESOLVER-391
>                 URL: https://issues.apache.org/jira/browse/MRESOLVER-391
>             Project: Maven Resolver
>          Issue Type: Bug
>          Components: Resolver
>            Reporter: Tamas Cservenak
>            Priority: Major
>             Fix For: 2.0.0
>
>
> As per MNG-5988: if an artifact in "test" scope is found nearer, but in scope 
> "compile" is found deeper in graph, the "test" scope wins. This at runtime 
> may lead to CNFEx.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to