Sort maven dependencies in Eclipse
Solution 1
Finally it is possible with Eclipse Photon now.
Just tick the checkbox Sort library entries alphabetically in Package Explorer
under Preferences
→ Java
→ Appearance
See also here under 'Sort library entries alphabetically in Package Explorer'.
Unfortunately theres a bug, at least for me, that the source folders are also reordered, see here.
Solution 2
I guess you refer to the m2eclipse plugin. You have these options:
The order in the navigator is the classpath order. You can sort the dependencies in the POM to get a better list. Of course, there is a problem with transient dependencies.
You can open the POM file in the POM editor and examine the dependencies in the tab "Dependency Hierarchy"
You can type part of the name of a dependency to locate it when the tree item "Maven Dependencies" is open.
Solution 3
Maven's Pom viewer will do the trick:
Double-click the pom.xml
you care about. Eclipse opens it in a special viewer with five tabs on the bottom: Overview, Dependencies, Dependency Hierarchy, Effective POM, and pom.xml.
Click Dependency Hierarchy
. You should see the following on the right side of the view:
It's alphabetized.
Solution 4
I just ran into the Sortpom Maven Plugin. This enables you to sort the dependencies in your pom using a Maven command. So you can use it in Eclipse, but also in any other IDE (I'm using NetBeans where you can configure it as custom goal definition).
Simply run:
mvn com.github.ekryd.sortpom:sortpom-maven-plugin:sort -Dsort.sortDependencies=groupId,artifactId
At the GitHub wiki you can find all parameters.
But as pointed out in the comments, sorting like this isn't a good idea. Let your IDE take care of it. NetBeans has a "Dependencies" folder in a project where the dependencies are shown sorted by default (first by type, then by name).
Solution 5
have a look at the project properties in the 'java build path' section under the 'libraries' tab.
i don't know for sure if this works for the m2eclipse plugin.
Related videos on Youtube
Sebastien Lorber
React expert & early adopter (January 2014) Freelance, working for Facebook/Meta as Docusaurus maintainer since 2020. Author of ThisWeekInReact.com, the best newsletter to stay up-to-date with the React ecosystem:
Updated on July 05, 2022Comments
-
Sebastien Lorber almost 2 years
Just wanted to know if it is possible in Eclipse to sort Maven dependencies by alphabetical order?
It's bothering me to have a list of 200 jars not ordered... :(
-
steffen over 5 yearsCould you change accepted answer to stackoverflow.com/a/52001216/845034?
-
Sebastien Lorber over 5 years@steffen ok done
-
-
Sean Patrick Floyd over 13 yearsDepressing. This is a good answer (+1), but the options are very unsatisfactory. Perhaps someone should file a feature request for an alphabetic order option, but I wouldn't know if that should be targeted at eclipse or at m2eclipse.
-
eis over 9 yearsIMO this is generally a bad idea, as Maven (as of version 2.0.9) uses deterministic classpath ordering based on order specified in POM. Sorting them around can easily mess up your build.
-
Adam Burley about 9 yearsUnfortunately, none of these options work: (1) does not fit with transient dependencies as you note, (2) you can see it there, but can't expand to see the packages/classes inside, (3) okay as long as you can EXACTLY type the artifact name without any prompt/feedback and without making any mistakes. For example, I was just looking for "selenium-remote-driver" in a list with half a dozen selenium JARs sprinkled throughout (all of which are prefixed with "selenium-") - to type "selenium-re" without making any mistakes and without seeing any feedback on-screen, is quite difficult.
-
Aaron Digulla over 8 years@Kidburla: Open "Maven Dependencies" in the package explorer. Type "sel" and then use Cursor-Up/Down to step through all instances which begin with these three letters.
-
Jake Toronto over 8 yearsThat actually IS sorted, and is a better solution than trying to manually scan the list to see whether your item is in there.
-
luis.espinal about 5 years@eis - FYi, the sortpom plugin does not sort modules or dependencies by default (because of that reason). It can be done if configured, and the documentation is clear about the warnings.
-
George almost 5 yearsNot alphabetized by default for me, had to click on the button "Sort" (on the top right corner in your screenshot)