我想知道:有没有办法使用Maven Dependency plug-in(或其他在命令行上),从存储库列出工件的传递依赖关系(即pom.xml
中的不)?
我知道可以使用mvn dependency:tree
列出我本地项目的依赖项,但我想知道之前的某些内容的依赖关系我将它添加到我的项目中(即做出明智的决定),并将依赖项添加到本地pom.xml
,唯一的目的是依赖插件似乎是hackish。
我希望我可以运行类似的东西:
mvn dependency:tree "-DgroupId=net.jawr" "-DartifactId=jawr-core" "-Dversion=3.5"
我提出的最好的是:
~/.m2/repository
)mvn dependency:get "-DgroupId=net.jawr" "-DartifactId=jawr-core" "-Dversion=3.5"
但这似乎非常 hackish and wasteful。
PS - 我不在乎它是否是树形格式。
答案 0 :(得分:19)
我不知道有任何本机方式使用Maven,但是,我想出了以下shell脚本,它似乎可以完成这项工作:
#!/bin/sh
if [ "$#" -ne 3 ]; then
echo "Usage: $0 <groupId> <artifactId> <version>"
exit
fi
POM_DIR="`echo "$1" | tr . /`/$2/$3"
POM_PATH="$POM_DIR/$2-$3.pom"
mkdir -p "$HOME/.m2/repository/$POM_DIR"
wget -q -O "$HOME/.m2/repository/$POM_PATH" "http://repo.maven.apache.org/maven2/$POM_PATH"
mvn -f "$HOME/.m2/repository/$POM_PATH" dependency:tree
此脚本从Maven Central Repository下载您指定的工件的POM,然后为该POM运行dependency:tree
目标。例如:
izstas@izstas-PC:~$ ./deptree net.jawr jawr-core 3.5
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Java web resources bundling and compression 3.5
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-dependency-plugin:2.1:tree (default-cli) @ jawr-core ---
[INFO] net.jawr:jawr-core:jar:3.5
[INFO] +- javax.servlet:servlet-api:jar:2.5:provided
[INFO] +- javax.servlet.jsp:jsp-api:jar:2.1:provided
[INFO] +- org.mozilla:rhino:jar:1.7R4:provided
[INFO] +- com.yahoo.platform.yui:yuicompressor:jar:2.4.7:provided
[INFO] +- javax.faces:jsf-api:jar:1.1_02:provided
[INFO] +- commons-validator:commons-validator:jar:1.2.0:provided
[INFO] | +- commons-beanutils:commons-beanutils:jar:1.7.0:provided
[INFO] | +- commons-digester:commons-digester:jar:1.6:provided
[INFO] | | \- commons-collections:commons-collections:jar:2.1:provided
[INFO] | +- commons-logging:commons-logging:jar:1.0.4:provided
[INFO] | +- oro:oro:jar:2.0.8:provided
[INFO] | \- xml-apis:xml-apis:jar:1.0.b2:provided
[INFO] +- taglibs:standard:jar:1.1.2:provided
[INFO] +- net.sf.ehcache:ehcache:jar:2.7.4:provided
[INFO] +- com.carrotsearch:smartsprites:jar:0.2.10:provided
[INFO] | +- com.google.guava:guava:jar:14.0.1:provided
[INFO] | +- args4j:args4j:jar:2.0.16:provided
[INFO] | +- org.apache.commons:commons-math3:jar:3.0:provided
[INFO] | +- commons-io:commons-io:jar:2.4:provided
[INFO] | \- org.apache.commons:commons-lang3:jar:3.1:provided
[INFO] +- com.google.javascript:closure-compiler:jar:v20131014:provided
[INFO] | +- com.google.protobuf:protobuf-java:jar:2.4.1:provided
[INFO] | +- org.json:json:jar:20090211:provided
[INFO] | \- com.google.code.findbugs:jsr305:jar:1.3.9:provided
[INFO] +- org.slf4j:slf4j-api:jar:1.7.5:compile
[INFO] +- org.slf4j:slf4j-log4j12:jar:1.7.5:provided
[INFO] +- log4j:log4j:jar:1.2.17:provided
[INFO] +- junit:junit:jar:4.11:test
[INFO] | \- org.hamcrest:hamcrest-core:jar:1.3:test
[INFO] \- org.mockito:mockito-all:jar:1.9.5:test
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.756s
[INFO] Finished at: Fri Mar 14 21:00:41 MSK 2014
[INFO] Final Memory: 10M/181M
[INFO] ------------------------------------------------------------------------
(如果我愿意,我可能会剥离不必要的Maven输出)
然而,这似乎下载.jar文件的依赖项,所以我不能说它是一个干净的解决方案。但至少它不需要您清除本地存储库。