Sort maven dependencies in Eclipse

JavaMaven 2DependenciesMavenDependency Management

Java Problem Overview


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... :(

Java Solutions


Solution 1 - Java

Finally it is possible with Eclipse Photon now.

Just tick the checkbox Sort library entries alphabetically in Package Explorer under PreferencesJavaAppearance

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.

preferences

Solution 2 - Java

I guess you refer to the m2eclipse plugin. You have these options:

  1. 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.

  2. You can open the POM file in the POM editor and examine the dependencies in the tab "Dependency Hierarchy"

  3. You can type part of the name of a dependency to locate it when the tree item "Maven Dependencies" is open.

Solution 3 - Java

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:

enter image description here

It's alphabetized.

Solution 4 - Java

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 - Java

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.

Solution 6 - Java

I had an issue where Sort library entries alphabetically in Package Explorer under PreferencesJavaAppearance was checked, but the dependencies were still unsorted.

Right clicking the library path and clicking Show in -> System Explorer fixed the issue for me.

enter image description here

Solution 7 - Java

It worked for me when I used the Java perspective instead of the Java EE perspective. On my computer, the dependencies were not sorted in the Java EE perspective, also not when I checked the checkbox in Java | Appearance. I had to choose the Java perspective instead. Then the checkbox did work and I could have sorted dependencies.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionSebastien LorberView Question on Stackoverflow
Solution 1 - JavaAndreas SchallerView Answer on Stackoverflow
Solution 2 - JavaAaron DigullaView Answer on Stackoverflow
Solution 3 - JavaJake TorontoView Answer on Stackoverflow
Solution 4 - JavaJasper de VriesView Answer on Stackoverflow
Solution 5 - JavaSalandurView Answer on Stackoverflow
Solution 6 - JavaGamebuster19901View Answer on Stackoverflow
Solution 7 - JavaMartijn DirkseView Answer on Stackoverflow