使用this method,我可以成功地解析(但不检索实际的jar)库的组织,名称和修订时的所有依赖关系,所有这些都是使用Apache Ivy以编程方式编写的。
在解析过程中,它会解析给定库的POM和finds a parent POM(如果已指定),而Ivy的POM解析器始终为tries to resolve sources and javadoc,这对于父POM通常不存在。
问题是当一个不存在的jar的URL被查询到我们的本地artifactory时,刷新它的缓存需要2~3秒,当我有很多时,需要花费几十分钟的总依赖解析时间具有父POM的传递依赖。
例如,以下是我尝试解析Google Guava 17.0时收到的日志消息:
:: loading settings :: url = jar:file:.ivy2/cache/org.apache.ivy/ivy/jars/ivy-2.3.0.jar!/org/apache/ivy/core/settings/ivysettings.xml
:: resolving dependencies :: com.google.guava#guava-envelope;17.0 [not transitive]
confs: [default]
validate = true
refresh = false
resolving dependencies for configuration 'default'
== resolving dependencies for com.google.guava#guava-envelope;17.0 [default]
== resolving dependencies com.google.guava#guava-envelope;17.0->com.google.guava#guava;17.0 [default->master]
tried http://artifactory/repo/com/google/guava/guava/17.0/guava-17.0.pom
resolver: found md file for com.google.guava#guava;17.0
=> http://artifactory/repo/com/google/guava/guava/17.0/guava-17.0.pom (17.0)
downloading http://artifactory/repo/com/google/guava/guava/17.0/guava-17.0.pom ...
resolver: downloading http://artifactory/repo/com/google/guava/guava/17.0/guava-17.0.pom
[SUCCESSFUL ] com.google.guava#guava;17.0!guava.pom(pom.original) (58ms)
tried http://artifactory/repo/com/google/guava/guava-parent/17.0/guava-parent-17.0.pom
resolver: found md file for com.google.guava#guava-parent;17.0
=> http://artifactory/repo/com/google/guava/guava-parent/17.0/guava-parent-17.0.pom (17.0)
downloading http://artifactory/repo/com/google/guava/guava-parent/17.0/guava-parent-17.0.pom ...
resolver: downloading http://artifactory/repo/com/google/guava/guava-parent/17.0/guava-parent-17.0.pom
[SUCCESSFUL ] com.google.guava#guava-parent;17.0!guava-parent.pom(pom.original) (20ms)
resolver: revision in cache: org.sonatype.oss#oss-parent;7
tried http://artifactory/repo/com/google/guava/guava-parent/17.0/guava-parent-17.0.jar
tried http://artifactory/repo/com/google/guava/guava-parent/17.0/guava-parent-17.0.jar
tried http://artifactory/repo/com/google/guava/guava-parent/17.0/guava-parent-17.0-sources.jar
CLIENT ERROR: Could not find resource url=http://artifactory/repo/com/google/guava/guava-parent/17.0/guava-parent-17.0-sources.jar
tried http://artifactory/repo/com/google/guava/guava-parent/17.0/guava-parent-17.0-src.jar
CLIENT ERROR: Could not find resource url=http://artifactory/repo/com/google/guava/guava-parent/17.0/guava-parent-17.0-src.jar
tried http://artifactory/repo/com/google/guava/guava-parent/17.0/guava-parent-17.0-javadoc.jar
CLIENT ERROR: Could not find resource url=http://artifactory/repo/com/google/guava/guava-parent/17.0/guava-parent-17.0-javadoc.jar
tried http://artifactory/repo/com/google/guava/guava/17.0/guava-17.0.jar
tried http://artifactory/repo/com/google/guava/guava/17.0/guava-17.0-sources.jar
tried http://artifactory/repo/com/google/guava/guava/17.0/guava-17.0-javadoc.jar
found com.google.guava#guava;17.0 in resolver
resolved ivy file produced in cache
:: resolution report :: resolve 2593ms :: artifacts dl 0ms
:: modules in use:
com.google.guava#guava;17.0 from resolver in [default]
---------------------------------------------------------------------
| | modules || artifacts |
| conf | number| search|dwnlded|evicted|| number|dwnlded|
---------------------------------------------------------------------
| default | 1 | 1 | 1 | 0 || 0 | 0 |
---------------------------------------------------------------------
report for com.google.guava#guava-envelope;17.0 default produced in .ivy2/cantabile/com.google.guava-guava-envelope-default.xml
resolve done (2593ms resolve - 0ms download)
您可以看到Ivy在为父POM尝试不存在的-sources.jar
,-src.jar
,-javadoc.jar
网址时浪费了几秒钟。
解析父POM时是否有禁用此行为的选项?理想情况下,我不希望在解析期间向任何.jar
发出HTTP请求。目前我需要一个程序化解决方案,但如果有人知道命令行/ XML选项,那将是一个很大的帮助。
PS:我认为使用sbt解析库依赖关系也是如此;解析oss-parent
,commons-parent
等需要很长时间。
答案 0 :(得分:0)
您需要指定一个配置映射,该映射排除可选依赖项和隐式依赖项(如source和javadoc文件)。
在常春藤文件中,您可以按如下方式声明依赖关系:
<dependency org="myorg" name="mymodule" rev="1.0" conf="default"/>
另一种选择是将此依赖关系映射声明为项目的默认值。
<dependencies defaultconfmapping="default">
<dependency ..
<dependency ..
请参阅以下有关如何排除源以及常春藤如何翻译Maven存储库的SO问题:
总之,Maven模块默认只有一个arefact。可以存储更多内容(如源和Javadoc),但没有列出它们的模块元数据。这就是为什么Ivy执行HTTP请求以查看是否存在人工制品的原因。更改配置映射设置应该有助于指导常春藤做正确的事:-)
PS
我认为这可以通过调用&#34; addDependencyConfiguration&#34; DefaultDependencyDescriptor对象的方法。