And here it is:
https://github.com/apache/maven/pull/1212

To have this tested, first build this
https://github.com/apache/maven-resolver/pull/322
then this:
https://github.com/apache/maven/pull/1212

And you will end up with maven:
- that fully delegates to resolver classpath ordering (removed all places
where they are "sorted", it is done by resolver)
- resolver supports "preOrder, "postOrder" and "levelOrder" transformation

Examples:
preOrder https://gist.github.com/cstamas/d1cb11d96938cdb9e6da2b46eec449b6
levelOrder https://gist.github.com/cstamas/6498cfb31afe74ded1471c02d982eee6

Observe how collected trees are TOTALLY SAME, but classpath order differs.

Thanks
T

On Thu, Jul 27, 2023 at 4:51 PM Tamás Cservenák <[email protected]> wrote:

> What a coincidence...
>
> I just started looking at an old issue (was looking at some edge cases)
> where even reproducer exists and tackles similar topic:
> https://issues.apache.org/jira/browse/MNG-6357
>
> Then I went to maven sources and resolver sources to ensure what is
> happening.
>
> Sadly, maven is not quite consistent in this matter, but is at least
> aligned:
> - at some places it uses PreorderNodeListGenerator to generate classpath
> (and/or ordered artifacts)
> - at some other places it relies on resolver ordering (that ALSO
> implicitly uses preorder)
>
> The class in question:
>
> https://github.com/apache/maven-resolver/blob/maven-resolver-1.9.14/maven-resolver-util/src/main/java/org/eclipse/aether/util/graph/visitor/PreorderNodeListGenerator.java
>
> The example output:
> https://gist.github.com/cstamas/ca113c1d6697540a4cf55c3098b9a550
>
> As you can see in example, the classpath is basically ordered as "reading
> the tree", this causes that for example maven-dependency-tree (2nd level
> dependency) comes BEFORE enforcer-api (1sd level) dependency.
>
> So, I myself find this wrong as well, but at least the statement you found
> "introduced deterministic ordering of dependencies on the classpath" still
> stands today: is PreOrder.
>
> Then occurred to me that this is easily customisable, so I went for start
> to create this:
> https://github.com/apache/maven-resolver/pull/322
>
> But this is only half of the story, as the Maven part is missing,
> especially where Maven sorts itself...
>
> All in all, an interesting coincidence....
>
> As for your other question: what resolver does is
> - builds a "dirty tree" (graph more precisely, it may have loops), we have
> two algorithms for this: original depth-first (DF) and new breadth-first
> (BF)
> - applies conflict resolution (this is where "winners" are set, ie.
> "closest wins" in case of duplicates)
> - resulted "clean tree" is transformed into list of (resolved) artifacts,
> possibly into classpath as well
> - OR the resolved graph is with class like (but
> consistently) PreorderNodeListGenerator used to create classpath -- so
> PreOrder is applied always
>
> Thanks
> T
>
>
> On Thu, Jul 27, 2023 at 3:51 PM <[email protected]>
> wrote:
>
>> Re-sending... didn't go through I think:
>>
>> In the release notes for Maven 2.0.9:
>>
>> http://people.apache.org/~jvanzyl/maven-3.1.1/docs/2.0.9/release-notes.html
>> It says: "introduced deterministic ordering of dependencies on the
>> classpath. In the past, natural set ordering was used and this lead to odd
>> results. The ordering is now preserved from your pom, with dependencies
>> added by inheritance added last"
>> Is this info still current?  Is it documented anywhere aside from this
>> release note?  If not, perhaps it should be?  And more details would be
>> nice too.  For instance:
>>
>> *         Suppose my module M has parent P and grandparent G.   Also, M
>> depends on A and B, in that order.  Further, suppose A depends on X, which
>> in turn depends on Y.  Meanwhile, B depends on Z.
>>
>> Based on the sentence above, both of these are plausible orders:
>>
>> a.    M, A, B, X, Z, Y, P, G
>>
>> b.    M, A, X, Y, B, Z, P, G
>>
>> c.     Maybe others too?
>>
>> *         How does this relate to the dependency "mediation" algorithm
>> maven uses when there are conflicting versions of a dependency requested?
>>
>> As far as I understand, that uses a breadth-first search, where the
>> parent pom comes FIRST rather than last.
>>
>> Does that mean that mediation algorithm is basically unrelated to class
>> path algorithm, or do they still have some things in common?
>>
>> E.g., ordering (a) above is also a breadth-first search, whereas (b) is
>> depth-first.
>> Any words of wisdom would be nice.
>>
>> Thanks,
>> Mark.
>>
>> This message is for information purposes only. It is not a
>> recommendation, advice, offer or solicitation to buy or sell a product or
>> service, nor an official confirmation of any transaction. It is directed at
>> persons who are professionals and is intended for the recipient(s) only. It
>> is not directed at retail customers. This message is subject to the terms
>> at: https://www.cib.barclays/disclosures/web-and-email-disclaimer.html.
>>
>> For important disclosures, please see:
>> https://www.cib.barclays/disclosures/sales-and-trading-disclaimer.html
>> regarding marketing commentary from Barclays Sales and/or Trading desks,
>> who are active market participants;
>> https://www.cib.barclays/disclosures/barclays-global-markets-disclosures.html
>> regarding our standard terms for Barclays Corporate and Investment Bank
>> where we trade with you in principal-to-principal wholesale markets
>> transactions; and in respect to Barclays Research, including disclosures
>> relating to specific issuers, see: http://publicresearch.barclays.com.
>> __________________________________________________________________________________
>>
>> If you are incorporated or operating in Australia, read these important
>> disclosures:
>> https://www.cib.barclays/disclosures/important-disclosures-asia-pacific.html
>> .
>>
>> __________________________________________________________________________________
>> For more details about how we use personal information, see our privacy
>> notice:
>> https://www.cib.barclays/disclosures/personal-information-use.html.
>>
>> __________________________________________________________________________________
>>
>

Reply via email to