I'd like to clarify one point about why I care about order:
I have a class name which clashes on purpose!
That is, I have a third-party dependency from maven central that does the Wrong 
Thing in one of its classes.
I have my own "fork" of that class which does the Right Thing.
I want to make sure that my version gets picked up!

-----Original Message-----
From: Tamás Cservenák <ta...@cservenak.net> 
Sent: Friday, July 28, 2023 5:29 PM
To: Maven Users List <users@maven.apache.org>
Subject: Re: enforcing class path order using maven enforcer


CAUTION: This email originated from outside our organisation - 
ta...@cservenak.net Do not click on links, open attachments, or respond unless 
you recognize the sender and can validate the content is safe.
Yup,

My "coinciding" work was not to fix people depending in cp ordering, but was 
more related to my guts telling that "level order" (introduced in experiment 
PR) is more correct than "pre order".

Latter may cause that your 3rd or 4th level transitive dep be enlisted on CP 
before your 2nd first level dependency (ie.if you consider a pom with 2 
dependencies, 1st dep nth level transitive dependency may "shadow" your 2nd 
direct dependency).

Thanks
T

On Fri, Jul 28, 2023, 23:14 Nick Stolwijk <nick.stolw...@gmail.com> wrote:

> Hi Tamás,
>
> Thanks for the corrections! I was still in the belief that it wasn't 
> explicitly ordered, but it seems that changed in the years. I still 
> think it is easier to reason about your application if you don't 
> depend on the order of dependencies. I have always used the Enforcer 
> plugin to at first give warnings about duplicate classes and later in 
> a project (when (almost) every duplicate was solved) to start failing 
> the build if someone introduced a new duplicate.
>
> I have seen a lot of "strange" behaviour because the IDE used a 
> different ordering than Maven did, and don't start about the runtime. 
> If you have duplicate classes and Maven "behaves", who says that the 
> runtime behaves in the same way?
>
> I would make it a bigger issue that you have duplicate classes, 
> instead of trying to live with those duplicates.
>
> With regards,
>
> Nick Stolwijk
>
> ~~~ Try to leave this world a little better than you found it and, 
> when your turn comes to die, you can die happy in feeling that at any 
> rate you have not wasted your time but have done your best ~~~
>
> Lord Baden-Powell
>
>
> On Fri, 28 Jul 2023 at 22:56, Tamás Cservenák <ta...@cservenak.net> wrote:
>
> > Nick,
> >
> > I have to correct you, as what you wrote is not true (anymore). But
> first,
> > I think this mail was on hold by moderator, as we had a same/similar 
> > discussion already on this thread:
> > https://clicktime.symantec.com/15t5jYwsx6K5Z7UziRch6?h=VKa9Ey2evQPqt
> > ITYTqeL8EywPKBX_Y4PmejsjmKDpPE=&u=https://lists.apache.org/thread/16
> > 055md5s2d5fqch5t4vkn13j7czfybr
> >
> > But in short:
> > - since 2.0.9 dependencies ARE ordered in deterministic way (unsure 
> > how), but since Maven 3+ they are pre-order (graph "flattened" into 
> > list, that
> is
> > then used to create CP and similar things)
> > - the plugins are ordered as well (and Maven 4 got or is about to 
> > get
> even
> > finer solution)
> > - and in above mentioned thread, this is where we at
> >
> >
> https://clicktime.symantec.com/15t5eikbVUdV9Af5AsDYU?h=sAaRELxca8Z4PlY
> jvO260Lq5WEBvkad0aTt_3p0wSb0=&u=https://issues.apache.org/jira/browse/
> MNG-6357?focusedCommentId%3D17748655%26page%3Dcom.atlassian.jira.plugi
> n.system.issuetabpanels%253Acomment-tabpanel%23comment-17748655
> > - for the rest (overlapping classes) I do agree fully, but life is
> life...
> >
> > HTH
> > T
> >
> > On Fri, Jul 28, 2023 at 10:45 PM Nick Stolwijk 
> > <nick.stolw...@gmail.com>
> > wrote:
> >
> > > Hi Mark,
> > >
> > > I don't think there is any guarantee for ordering in Maven. The 
> > > dependencies are not ordered, the plugins in the build section are 
> > > not ordered. I remember that with a Java upgrade the plugins were 
> > > executed
> > in a
> > > different ordering due to a new implementation of HashMap. (Only 
> > > the plugins in the same phase in a lifecycle, of course). The only 
> > > thing ordered are the phases in the lifecycle.
> > >
> > > I think it would be more feasible to make sure you don't have
> > dependencies
> > > with overlapping classes (you can use the Maven Enforcer Plugin 
> > > for that[1]). If you really need those 2 dependencies on the 
> > > classpath,
> maybe
> > > you can try something with the Maven Shade Plugin, to give one of 
> > > those dependencies their unique package names[2].
> > >
> > > [1]
> > https://clicktime.symantec.com/15t6QCW9d1mprg6P4tot4?h=37l3X1rUMHCNa
> > zx5tx73nMPMatZatBRkIVE73EVfz5s=&u=https://www.mojohaus.org/extra-enf
> > orcer-rules/banDuplicateClasses.html
> > > [2]
> > >
> > >
> >
> https://clicktime.symantec.com/15t5pP9AQhzfy4JvFz1qi?h=454YA129nQl0eUE
> Uetl13kca-YVeudTafYsvmeO1vd0=&u=https://maven.apache.org/plugins/maven
> -shade-plugin/examples/class-relocation.html
> > >
> > > Hth,
> > >
> > > Nick Stolwijk
> > >
> > > ~~~ Try to leave this world a little better than you found it and, 
> > > when your turn comes to die, you can die happy in feeling that at 
> > > any rate
> you
> > > have not wasted your time but have done your best ~~~
> > >
> > > Lord Baden-Powell
> > >
> > >
> > > On Fri, 28 Jul 2023 at 21:25, 
> > > <mark.yagnatin...@barclays.com.invalid>
> > > wrote:
> > >
> > > > I already asked this question on Stack Overflow but got no 
> > > > takers so
> > I'm
> > > > trying again here:
> > > >
> > > > Suppose I have a maven module M which declares a direct 
> > > > dependency on modules X and Y.
> > > > I want the classes from X to come before classes from Y in the 
> > > > class
> > > path.
> > > > Is there any easy way to add a rule in maven enforcer to ensure 
> > > > that
> I
> > > > don't accidentally swap the order sometime in the future?
> > > >
> > > > Copied from here:
> > > >
> > > >
> > >
> >
> https://clicktime.symantec.com/15t5uDLSsKgGP18qoYQzL?h=7EsniQcHdjM6TWA
> LQmIQCb3sq4YQHFeY033chmgMmio=&u=https://stackoverflow.com/questions/76
> 766623/maven-enforcer-enforce-class-path-order
> > > >
> > > >
> > > > 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://clicktime.symantec.com/15t6KNJsAQ6ESjGTXLQjS?h=UYic_JXsxcpL2aF1JEpHtd_IKig2nm08TfffhuM3isI=&u=https://www.cib.barclays/disclosures/web-and-email-disclaimer.html.
> > > >
> > > > For important disclosures, please see:
> > > >
> https://clicktime.symantec.com/15t6EY7ahnQe2nSXyn1ap?h=3yPmimR8ZeJmRI1
> Qrhr5Iz1WBozTWiLZY6jnjTIL5WU=&u=https://www.cib.barclays/disclosures/s
> ales-and-trading-disclaimer.html
> > > > regarding marketing commentary from Barclays Sales and/or 
> > > > Trading
> > desks,
> > > > who are active market participants;
> > > >
> > >
> >
> https://clicktime.symantec.com/15t5z3XjKwMrnwxmM6p8x?h=nnifedQWQSIN0hF
> ZZCphqp2eD_UPYsXCh03glxrZv0E=&u=https://www.cib.barclays/disclosures/b
> arclays-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:
> https://clicktime.symantec.com/15t5ZtZK2rwtjDq9dJpPr?h=ebFuluTMuHrujaXg7BbA6RFvI3sVnJosEx6rvhG3whQ=&u=http://publicresearch.barclays.com.
> > > >
> > >
> >
> ______________________________________________________________________
> ____________
> > > >
> > > > If you are incorporated or operating in Australia, read these
> important
> > > > disclosures:
> > > >
> > >
> >
> https://clicktime.symantec.com/15t64sj1nZ3TCtngtfDHa?h=amyGj5lckrWHDr6
> zgTItvkj4U9D2J4Cuf_bbIvQD9n8=&u=https://www.cib.barclays/disclosures/i
> mportant-disclosures-asia-pacific.html
> > > > .
> > > >
> > > >
> > >
> >
> ______________________________________________________________________
> ____________
> > > > For more details about how we use personal information, see our
> privacy
> > > > notice:
> > > https://clicktime.symantec.com/15t69hvJFAj3cqccSDcSC?h=_BB12LrslSf75XH6-ndRMcBbzwMd5gE9uHGHB7VdVIk=&u=https://www.cib.barclays/disclosures/personal-information-use.html.
> > > >
> > > >
> > > >
> > >
> >
> ______________________________________________________________________
> ____________
> > > >
> > >
> >

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