简体   繁体   中英

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

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

...

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:

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").

您可以使用Maven Dependency Plugin来分析POM的依赖关系。

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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