是否有一种方法可以列出maven项目的依赖关系而无需下载jar ?我知道有maven依赖插件可用。
mvn dependency:tree
或
mvn dependency:list
但是,两者都将尝试下载jar。可以跳过jar的下载阶段吗?还有别的办法吗?例如:使用不同的工具。
发现有目标
mvn dependency:collect
但是,这只会下载依赖项,它不适用于工件。
我今天遇到了同样的问题,在网上找不到任何解决方案。尤其是这里;)
如果你不想列出可传递的依赖项,请在下面找到一个肮脏而又棘手的解决方案。(顺便说一句,我认为不下载pom是不可能列出传递依赖关系的):
export GROUPID=org.springframework
export ARTIFACTID=spring-context
export VERSION=5.3.16
首先我们得到所需GAV的POM:
mvn dependency:get -Dtransitive=false -DgroupId=${GROUPID} -DartifactId=${ARTIFACTID} -Dversion=${VERSION} -Dpackaging=pom
这里我们TRY解析中的依赖项和模式:
mvn -f -o -X ~/.m2/repository/`echo "${GROUPID}/${ARTIFACTID}" | sed 's/.///'`/${VERSION}/*.pom dependency:list -DexcludeTransitive
mvn将失败,输出中有一些有趣的行:
[DEBUG] Dependency collection stats {ConflictMarker.analyzeTime=365032, ConflictMarker.markTime=106055, ConflictMarker.nodeCount=5, ConflictIdSorter.graphTime=201747, ConflictIdSorter.topsortTime=214050, ConflictIdSorter.conflictIdCount=4, ConflictIdSorter.conflictIdCycleCount=0, ConflictResolver.totalTime=1708152, ConflictResolver.conflictItemCount=4, DefaultDependencyCollector.collectTime=4415754, DefaultDependencyCollector.transformTime=3650266}
[DEBUG] org.springframework:spring-context:jar:5.3.16
[DEBUG] org.springframework:spring-aop:jar:5.3.16:compile
[DEBUG] org.springframework:spring-beans:jar:5.3.16:compile
[DEBUG] org.springframework:spring-core:jar:5.3.16:compile
[DEBUG] org.springframework:spring-expression:jar:5.3.16:compile
我们可以看到它是一个依赖项列表。它在mvn失败之前出现。
PS:我不推荐它用于生产环境。只适合一次性作业