[英]How to find maven dependencies of any given project?
I am trying to building a separate project which can find maven dependencies of any given project.我正在尝试构建一个单独的项目,该项目可以找到任何给定项目的 Maven 依赖项。 I was referring Aether samples but i could not find a way to define another project to find dependencies.
我指的是 Aether 示例,但我找不到定义另一个项目以查找依赖项的方法。
As shown in the following figure 1 , Project 1 has dependencies of project 2 and project 2 has dependencies of project 3. If i select project 1 on dependency finder it should show all the dependencies of project 1 which are project 2.如下图1所示,项目 1 具有项目 2 的依赖项,项目 2 具有项目 3 的依赖项。如果我在依赖项查找器上选择项目 1,它应该显示项目 1 的所有依赖项,即项目 2。
I was referring following Aether code piece but i could not figure out a way to set another project (by setting pom file or project directory)我指的是以下 Aether 代码片段,但我无法找到设置另一个项目的方法(通过设置 pom 文件或项目目录)
RepositorySystem system = Booter.newRepositorySystem();
RepositorySystemSession session = Booter.newRepositorySystemSession( system );
Artifact artifact = new DefaultArtifact( "org.eclipse.aether:aether-impl:1.0.0.v20140518" );
ArtifactDescriptorRequest descriptorRequest = new ArtifactDescriptorRequest();
descriptorRequest.setArtifact( artifact );
descriptorRequest.setRepositories( Booter.newRepositories( system, session ) );
ArtifactDescriptorResult descriptorResult = system.readArtifactDescriptor( session, descriptorRequest );
for ( Dependency dependency : descriptorResult.getDependencies() )
{
System.out.println( dependency );
}
You don't need to do it programatically.您不需要以编程方式执行此操作。 You could simply invoke dependency:tree :
您可以简单地调用dependency:tree :
mvn dependency:tree
I would also recommend you invoke it with -Dverbose
in case you're really, really having a hard time figuring why a certain version of a dependency is being chosen over another one (which you may be expecting it to be using instead).我还建议您使用
-Dverbose
调用它,以防您真的、真的很难弄清楚为什么选择某个版本的依赖项而不是另一个版本(您可能希望它使用它)。
Or, alternatively, if you'd like to see the dependencies in a flat form, you could also use dependency:list或者,如果您想以平面形式查看依赖项,也可以使用dependency:list
mvn dependency:list
如果您使用带有 maven2 插件的 eclipse,那么当您打开 pom 文件时,它会显示几个视图以根据您的要求查看依赖项。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.