maven2 - how to list all resources repository url from pom file

╄→尐↘猪︶ㄣ 提交于 2019-12-10 15:59:06

问题


I'm looking for something like this:

List<URL> urls = listURLFromPOM("c:\pom.xml");

..

http://repo1.maven.org/maven2/org/apache/ibatis/ibatis-core/3.0/ibatis-core-3.0.jar
http://repo1.maven.org/maven2/org/apache/camel/camel-activemq/1.1.0/camel-activemq-1.1.0.jar

...

回答1:


You can use the Maven Dependency Plugin to analyze the dependencies of you POM.

mvn dependency:list -DoutputAbsoluteArtifactFilename=true -DoutputFile=dependencies.txt



回答2:


A dependency is not aware of its "source repository" which might not be unique so you won't be able to get the "source URL" of a dependency without actually resolving it. One way to do that (without writing code using Maven internal APIs) would be to use dependency:purge-local-repository. From the Maven Dependency Plugin documentation:

  • dependency:purge-local-repository tells Maven to clear all dependency-artifact files out of the local repository, and optionally re-resolve them.

Run that command and redirect the output to a file for post-processing:

mvn dependency:purge-local-repository > raw.txt

As I just mentioned, if you are using several repositories, you might need to do some post processing to separate the "successful" download from "failed" attempts. Here is a sample regex on Rubular that might be helpful to implement such a post-processing (I provided some content illustrating the "problem").



来源:https://stackoverflow.com/questions/3258475/maven2-how-to-list-all-resources-repository-url-from-pom-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!