Maven 2.x Eclipse Plugin

Write .classpath with ordered dependencies [incl. Patch]

Details

  • Type: Improvement Improvement
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: 2.2
  • Fix Version/s: 2.5
  • Component/s: None
  • Labels:
    None
  • Environment:
    Windowz XP, eclipse 3.2
  • Number of attachments :
    2

Description

Related to my comment in MNG-1412 - I decided to take a quick stab at the eclipse plugin and voilá! Ordered dependencies in the written .classpath. This is only a prototype (my first attempt at maven development) and could serve as basis for other orderings like groupId, transitive nearness etc.

Initially I wanted to make IdeDependency comparable (similar to MECLIPSE-150 which added proper equals) but having multiple Comparators seemed better for extensibility.

It worked right away, does exactly what I want (ordering by artifactId) and has minimal impact. I am not familiar with the maven codebase so I hope this is the right place to do the actual ordering before writing; obviously it should observe a property like -DorderDependencies=artifactId or something similar. The patch is against svn r425750 (2006-08-30). Currently no testcase but if someone tells me how to add/read an orderDependencies property I might add one.

Comments welcome.

  1. orderDependencies.patch
    30/Aug/06 10:06 AM
    3 kB
    Holger Hoffstätte
  2. orderDependencies.patch
    30/Aug/06 7:14 AM
    3 kB
    Holger Hoffstätte

Issue Links

Activity

Hide
Holger Hoffstätte added a comment -

update to correctly sort upper/lowercase dependencies

Show
Holger Hoffstätte added a comment - update to correctly sort upper/lowercase dependencies
Hide
Philip Maher added a comment -

I'd like to throw my support behind this idea and request that a transitive nearness ordering be added as well.

Show
Philip Maher added a comment - I'd like to throw my support behind this idea and request that a transitive nearness ordering be added as well.
Hide
Kenney Westerhof added a comment -

Crap. I wrote a few Kb and accidently closed the window. I hate web-guis.

Short story:

continuum-release depends on:

  • maven-project 2.0.4
  • maven-release-plugin, which depends on maven-project 2.0

In eclipse, maven-release-plugin is listed before maven-project-2.0.4.jar.

Due to an API change (ProjectSorter added another exception in 2.0.4), I get an error in eclipse,
because the code catches the exception defined in 2.0.4 but eclipse sees the implementation
from 2.0 which doesn't throw that.

So I suggest we ONLY support ordering for transitive dependencies. However, there are a few options:

  • sort projects by transitive dependencies, so that the correct version is resolved. This is impossible, because two projects could be considered to be listed before eachoter:

MAIN depends on A and B.
A depends on C 1.0 and D 1.1
B depends on C 1.1 and D 1.0.
MAIN depends on C 1.0 and D 1.0.

No way to order this properly, A needs to come before B because of C, and B needs to come before A because of D.

  • Simplest solution: do NOT export any dependencies, and list all transitive dependencies explicitly. This is done already for
    non-workspace dependencies, but should also be done for workspace project references.

I had some hybrid solutions but the above cover the extremes.

Show
Kenney Westerhof added a comment - Crap. I wrote a few Kb and accidently closed the window. I hate web-guis. Short story: continuum-release depends on:
  • maven-project 2.0.4
  • maven-release-plugin, which depends on maven-project 2.0
In eclipse, maven-release-plugin is listed before maven-project-2.0.4.jar. Due to an API change (ProjectSorter added another exception in 2.0.4), I get an error in eclipse, because the code catches the exception defined in 2.0.4 but eclipse sees the implementation from 2.0 which doesn't throw that. So I suggest we ONLY support ordering for transitive dependencies. However, there are a few options:
  • sort projects by transitive dependencies, so that the correct version is resolved. This is impossible, because two projects could be considered to be listed before eachoter:
MAIN depends on A and B. A depends on C 1.0 and D 1.1 B depends on C 1.1 and D 1.0. MAIN depends on C 1.0 and D 1.0. No way to order this properly, A needs to come before B because of C, and B needs to come before A because of D.
  • Simplest solution: do NOT export any dependencies, and list all transitive dependencies explicitly. This is done already for non-workspace dependencies, but should also be done for workspace project references.
I had some hybrid solutions but the above cover the extremes.
Hide
Holger Hoffstätte added a comment -

Kenney, none of your examples show why having an alphabetic ordering should not be at least an option. I don't see why people with correctly managed dependencies have to suffer from other people's mistakes, like your example where an ABI break in maven requires messing with the build system. Using the build system to fix this is the wrong solution to the right problem (yes I understand that sometimes it's necessary in "the real world", wherever that is); your second example even shows why the assumption that transitive dependencies are always correct becomes more and more likely to break down as the number of dependencies increases. Add some m1-converted POMs with changed groupIds and the whole concept simply stops working "in the real world". Also as long as the dependency list in eclipse is flattened, the fact that it is transitively ordered becomes less than helpful because you cannot see where a dependency level starts and stops.
My workspace contains >30 projects with sometimes >80 dependencies each and trying to resolve duplicates or conflicts (keywords: XML, JMX, other API/implementation conflicts, different profiles for JDK 1.4/1.5) caused by broken POMs was simply not reasonably possible without ordering by name to quickly see offending jars.

Show
Holger Hoffstätte added a comment - Kenney, none of your examples show why having an alphabetic ordering should not be at least an option. I don't see why people with correctly managed dependencies have to suffer from other people's mistakes, like your example where an ABI break in maven requires messing with the build system. Using the build system to fix this is the wrong solution to the right problem (yes I understand that sometimes it's necessary in "the real world", wherever that is); your second example even shows why the assumption that transitive dependencies are always correct becomes more and more likely to break down as the number of dependencies increases. Add some m1-converted POMs with changed groupIds and the whole concept simply stops working "in the real world". Also as long as the dependency list in eclipse is flattened, the fact that it is transitively ordered becomes less than helpful because you cannot see where a dependency level starts and stops. My workspace contains >30 projects with sometimes >80 dependencies each and trying to resolve duplicates or conflicts (keywords: XML, JMX, other API/implementation conflicts, different profiles for JDK 1.4/1.5) caused by broken POMs was simply not reasonably possible without ordering by name to quickly see offending jars.
Hide
Kenney Westerhof added a comment -

Hm, actually, when I just disable the 'exported' flag on dependencies, the problem above goes away.

I tested reordering the dependencies but this doesn't work in eclipse 3.2. Even though the correct dep
is listed first, it still resolves to the second one. Weird.

Show
Kenney Westerhof added a comment - Hm, actually, when I just disable the 'exported' flag on dependencies, the problem above goes away. I tested reordering the dependencies but this doesn't work in eclipse 3.2. Even though the correct dep is listed first, it still resolves to the second one. Weird.
Hide
Kenney Westerhof added a comment -

You're right. I created a separate issue (MECLIPSE-170) to address the erroneous classpath issue.

As for the sorting on names, that's a really good idea since I'm always searching huge lists of dependencies to see if a jar is in there.

Show
Kenney Westerhof added a comment - You're right. I created a separate issue (MECLIPSE-170) to address the erroneous classpath issue. As for the sorting on names, that's a really good idea since I'm always searching huge lists of dependencies to see if a jar is in there.
Hide
fabrizio giustina added a comment -

scheduling for 2.3: at this moment only osgi dependencies in manifest are sorted

Show
fabrizio giustina added a comment - scheduling for 2.3: at this moment only osgi dependencies in manifest are sorted
Hide
Joerg Buchberger added a comment -

As for the convenience of finding particular dependencies in eclipse build path more quickly, I'd suggest the following
SORT OPTIONS:

  • by artifactId
  • by groupId

However, I consider it more important to have the option to control CLASSPATH ORDER by sorting classpath entries
according to the order of dependencies as written in the POM. At least for runtime dependencies.
This would make it unnecessary to manually adjust classpath order in eclipse and reduce time for supporting
developers who are unexperienced or new to the project...

Show
Joerg Buchberger added a comment - As for the convenience of finding particular dependencies in eclipse build path more quickly, I'd suggest the following SORT OPTIONS:
  • by artifactId
  • by groupId
However, I consider it more important to have the option to control CLASSPATH ORDER by sorting classpath entries according to the order of dependencies as written in the POM. At least for runtime dependencies. This would make it unnecessary to manually adjust classpath order in eclipse and reduce time for supporting developers who are unexperienced or new to the project...
Hide
Mark Hobson added a comment -

Does this change not need to be made in maven core (MNG-1412) rather than just this plugin? Otherwise it could lead to different results between building a project in the cmdline and within eclipse.

Show
Mark Hobson added a comment - Does this change not need to be made in maven core (MNG-1412) rather than just this plugin? Otherwise it could lead to different results between building a project in the cmdline and within eclipse.
Hide
Brian Fox added a comment -

Note that in MECLIPSE-294, it is noted that this particular randomness causes problems in the unit tests.

Show
Brian Fox added a comment - Note that in MECLIPSE-294, it is noted that this particular randomness causes problems in the unit tests.
Hide
Arnaud Heritier added a comment -

Patch applied.
Dependencies are now sorted by artifactId instead to have a random sort.
It's only a wordaround, which could disappear in the feature if maven's core has a policy for dependencies order.

Show
Arnaud Heritier added a comment - Patch applied. Dependencies are now sorted by artifactId instead to have a random sort. It's only a wordaround, which could disappear in the feature if maven's core has a policy for dependencies order.
Hide
Max Bowsher added a comment -

Please re-open this issue. A sort by artifactId is not sufficient. Part of the reason for desiring sorting is so that the generated classpaths in the plugins own tests are consistent - some of these contain entries which differ only in classifier, so the classifier it is necessary that the classifier be included in the sort criteria.

For a full solution, the sort key should probably include groupId+artifactId+type+classifier - i.e. the criteria applied by Maven in DefaultArtifact.getDependencyConflictId().

Show
Max Bowsher added a comment - Please re-open this issue. A sort by artifactId is not sufficient. Part of the reason for desiring sorting is so that the generated classpaths in the plugins own tests are consistent - some of these contain entries which differ only in classifier, so the classifier it is necessary that the classifier be included in the sort criteria. For a full solution, the sort key should probably include groupId+artifactId+type+classifier - i.e. the criteria applied by Maven in DefaultArtifact.getDependencyConflictId().
Hide
Holger Hoffstätte added a comment -

Max, your "full solution" would do something completely different than what I originally intended, which is pretty much your solution without the groupId. There cannot be a single "unified" solution! eclipse has no notion of "groups" and trying to somehow model maven concepts on top of the .classpath will just lead to a great deal of confusion. artifact "ordering" is a very arbitrary and project-dependent concept, which is why I said from the very beginning that multiple comparators need to be selectable. I merely provided the first (one possible) implementation.

Show
Holger Hoffstätte added a comment - Max, your "full solution" would do something completely different than what I originally intended, which is pretty much your solution without the groupId. There cannot be a single "unified" solution! eclipse has no notion of "groups" and trying to somehow model maven concepts on top of the .classpath will just lead to a great deal of confusion. artifact "ordering" is a very arbitrary and project-dependent concept, which is why I said from the very beginning that multiple comparators need to be selectable. I merely provided the first (one possible) implementation.
Hide
Max Bowsher added a comment -

Ah, I admit I had not actually read this issue, I was going to comment on MECLIPSE-294, but then noticed that it had been closed as duplicate of this issue, so I followed the "duplicates" link and put my comment here instead.

Right. Having read this issue, I can see that whilst the committed fix solves the concerns of this issue, it does not fix the MECLIPSE-294 - so I'm going to unduplicate the two issues.

Show
Max Bowsher added a comment - Ah, I admit I had not actually read this issue, I was going to comment on MECLIPSE-294, but then noticed that it had been closed as duplicate of this issue, so I followed the "duplicates" link and put my comment here instead. Right. Having read this issue, I can see that whilst the committed fix solves the concerns of this issue, it does not fix the MECLIPSE-294 - so I'm going to unduplicate the two issues.

People

Vote (9)
Watch (9)

Dates

  • Created:
    Updated:
    Resolved: