简体   繁体   English

在Eclipse中排序maven依赖

[英]Sort maven dependencies in Eclipse

Just wanted to know if it is possible in Eclipse to sort Maven dependencies by alphabetical order?只是想知道是否可以在 Eclipse 中按字母顺序对 Maven 依赖项进行排序?

It's bothering me to have a list of 200 jars not ordered... :(有一份 200 jars 未订购的清单让我很困扰......:(

Finally it is possible with Eclipse Photon now.现在终于可以使用 Eclipse Photon 了。

Just tick the checkbox Sort library entries alphabetically in Package Explorer under PreferencesJavaAppearance只需在PreferencesJavaAppearance下的Sort library entries alphabetically in Package Explorer复选框

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 .不幸的是,至少对我而言,存在一个错误,即源文件夹也被重新排序,请参见此处

偏好

I guess you refer to the m2eclipse plugin.我猜你指的是 m2eclipse 插件。 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.您可以对 POM 中的依赖项进行排序以获得更好的列表。 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"您可以在 POM 编辑器中打开 POM 文件,并在“依赖层次结构”选项卡中检查依赖关系

  3. You can type part of the name of a dependency to locate it when the tree item "Maven Dependencies" is open.当树项“Maven Dependencies”打开时,您可以键入依赖项的部分名称来定位它。

Maven's Pom viewer will do the trick: Maven 的 Pom 查看器可以解决这个问题:

Double-click the pom.xml you care about.双击你关心的pom.xml Eclipse opens it in a special viewer with five tabs on the bottom: Overview, Dependencies, Dependency Hierarchy, Effective POM, and pom.xml. Eclipse 在一个特殊的查看器中打开它,底部有五个选项卡:Overview、Dependencies、Dependency Hierarchy、Effective POM 和 pom.xml。

Click Dependency Hierarchy .单击Dependency Hierarchy You should see the following on the right side of the view:您应该在视图的右侧看到以下内容:

在此处输入图片说明

It's alphabetized.它是按字母顺序排列的。

I just ran into the Sortpom Maven Plugin .我刚刚遇到了Sortpom Maven Plugin This enables you to sort the dependencies in your pom using a Maven command.这使您可以使用 Maven 命令对 pom 中的依赖项进行排序。 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).因此,您可以在 Eclipse 中使用它,也可以在任何其他 IDE 中使用它(我使用的是 NetBeans,您可以在其中将其配置为自定义目标定义)。

Simply run:只需运行:

mvn com.github.ekryd.sortpom:sortpom-maven-plugin:sort -Dsort.sortDependencies=groupId,artifactId

At the GitHub wiki you can find all parameters .在 GitHub wiki 您可以找到所有参数

But as pointed out in the comments, sorting like this isn't a good idea.但正如评论中指出的那样,这样排序并不是一个好主意。 Let your IDE take care of it.让您的 IDE 来处理它。 NetBeans has a "Dependencies" folder in a project where the dependencies are shown sorted by default (first by type, then by name). NetBeans 在一个项目中有一个“Dependencies”文件夹,其中默认显示依赖项(首先按类型,然后按名称)。

It worked for me when I used the Java perspective instead of the Java EE perspective.当我使用 Java 透视图而不是 Java EE 透视图时,它对我有用。 On my computer, the dependencies were not sorted in the Java EE perspective, also not when I checked the checkbox in Java |在我的电脑上,依赖项没有在 Java EE 透视图中排序,当我在 Java | 中选中复选框时也没有排序。 Appearance.外貌。 I had to choose the Java perspective instead.我不得不选择 Java 视角。 Then the checkbox did work and I could have sorted dependencies.然后复选框确实起作用了,我可以对依赖项进行排序。

have a look at the project properties in the 'java build path' section under the 'libraries' tab.查看“库”选项卡下“java 构建路径”部分中的项目属性。

i don't know for sure if this works for the m2eclipse plugin.我不确定这是否适用于 m2eclipse 插件。

I had an issue where Sort library entries alphabetically in Package Explorer under PreferencesJavaAppearance was checked, but the dependencies were still unsorted.我遇到了一个问题, Java Sort library entries alphabetically in Package Explorer进行排序 → PreferencesAppearance已检查,但依赖项仍未排序。

Right clicking the library path and clicking Show in -> System Explorer fixed the issue for me.右键单击库路径并单击Show in -> System Explorer为我解决了这个问题。

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM