java 在 Eclipse 中对 Maven 依赖项进行排序
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3812894/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Sort maven dependencies in Eclipse
提问by Sebastien Lorber
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 个罐子的清单让我很困扰……:(
采纳答案by Andreas Schaller
Finally it is possible with Eclipse Photon now.
现在终于可以使用 Eclipse Photon 了。
Just tick the checkbox Sort library entries alphabetically in Package Explorer
under Preferences
→ Java
→ Appearance
只需勾选→ →Sort library entries alphabetically in Package Explorer
下的复选框Preferences
Java
Appearance
See also hereunder 'Sort library entries alphabetically in Package Explorer'.
另请参阅“在包资源管理器中按字母顺序对库条目进行排序”下的此处。
Unfortunately theres a bug, at least for me, that the source folders are also reordered, see here.
不幸的是,至少对我而言,存在一个错误,即源文件夹也被重新排序,请参见此处。
回答by Aaron Digulla
I guess you refer to the m2eclipse plugin. You have these options:
我猜你指的是 m2eclipse 插件。您有以下选择:
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.
导航器中的顺序是类路径顺序。您可以对 POM 中的依赖项进行排序以获得更好的列表。当然,瞬态依赖是有问题的。
您可以在 POM 编辑器中打开 POM 文件,并在“Dependency Hierarchy”选项卡中检查依赖关系
当树项“Maven Dependencies”打开时,您可以键入依赖项的部分名称来定位它。
回答by Jake Toronto
Maven's Pom viewer will do the trick:
Maven 的 Pom 查看器可以解决这个问题:
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.
双击pom.xml
您关心的。Eclipse 在一个特殊的查看器中打开它,底部有五个选项卡:Overview、Dependencies、Dependency Hierarchy、Effective POM 和 pom.xml。
Click Dependency Hierarchy
. You should see the following on the right side of the view:
单击Dependency Hierarchy
。您应该在视图的右侧看到以下内容:
It's alphabetized.
它是按字母顺序排列的。
回答by Jasper de Vries
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).
我刚刚遇到了Sortpom Maven Plugin。这使您能够使用 Maven 命令对 pom 中的依赖项进行排序。因此,您可以在 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. NetBeans has a "Dependencies" folder in a project where the dependencies are shown sorted by default (first by type, then by name).
但正如评论中指出的那样,这样排序并不是一个好主意。让您的 IDE 来处理它。NetBeans 在一个项目中有一个“Dependencies”文件夹,其中默认显示依赖项(首先按类型,然后按名称)。
回答by Salandur
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 插件。