我有以下常春藤文件:
<configurations defaultconfmapping="buildtime">
<conf name="buildtime" visibility="private" description="Libraries needed only for compilation" />
<conf name="runtime" description="Libraries only needed at runtime" />
<conf name="test" description="Libraries only needed for testing" />
</configurations>
<dependencies>
<dependency org="net.java.dev" name="jvyaml" rev="0.2.1" conf="runtime" />
<dependency org="org.apache.solr" name="solr-core" rev="3.6.0" conf="runtime" />
</dependencies>
Run Code Online (Sandbox Code Playgroud)
我有一个如下所示的ant检索任务:
<target name="retrieve-all" depends="resolve">
<ivy:retrieve pattern="lib/[conf]/[artifact]-[revision].[ext]" conf="*" />
</target>
Run Code Online (Sandbox Code Playgroud)
奇怪的是,所有solr依赖项都按照我的预期下载到lib/runtime中,但是jvyaml模块没有!它'解析',但不会下载到lib/runtime目录,除非我将依赖声明更改为:
<dependency org="net.java.dev" name="jvyaml" rev="0.2.1" conf="runtime->master" />
Run Code Online (Sandbox Code Playgroud)
什么是主配置,为什么需要拉jvyaml jar,但不是solr?
谢谢
Mar*_*nor 20
我建议重构您的配置如下:
<ivy-module version="2.0">
<info organisation="com.myspotontheweb" module="demo"/>
<configurations>
<conf name="compile" description="Libraries needed only for compilation" />
<conf name="runtime" description="Libraries only needed at runtime" extends="compile" />
<conf name="test" description="Libraries only needed for testing" extends="runtime" />
</configurations>
<dependencies>
<dependency org="net.java.dev" name="jvyaml" rev="0.2.1" conf="runtime->default" />
<dependency org="org.apache.solr" name="solr-core" rev="3.6.0" conf="runtime->default" />
</dependencies>
</ivy-module>
Run Code Online (Sandbox Code Playgroud)
引入的重要变化:
配置是强大的常春藤功能.当ivy下载Maven模块时,它会执行内部翻译并分配一组标准配置,在此答案中列出:
在声明依赖项时,始终使用配置映射是个好主意,因此毫无疑问,依赖项工件的分配位置.
例如:
<dependency org="??" name="??" rev="??" conf="runtime->default" />
Run Code Online (Sandbox Code Playgroud)
这里我们说我们希望远程模块的默认依赖关系与我们的本地运行时配置相关联.
实际上,实际上只需要两个远程配置映射:
总而言之,我认为您的问题是由于远程Maven模块的"运行时"范围不包含Maven模块的工件这一事实,而是您获得了模块jvyaml的非存在传递依赖性:-(
我还建议生成一个常春藤依赖管理报告,如下所示:
<target name="init" description="Resolve dependencies and populate lib dir">
<ivy:resolve/>
<ivy:report todir="${build.dir}/ivy-report" graph="false"/>
<ivy:retrieve pattern="lib/[conf]/[artifact]-[revision].[ext]"/>
</target>
Run Code Online (Sandbox Code Playgroud)
该报告将帮助解释每个依赖关系如何在不同的配置上结束.对于确定如何管理传递依赖性也非常有用.
最后,这里是配置继承得到回报的地方,创建了常春藤管理的ANT类路径:
<target name="init" description="Resolve dependencies and set classpaths">
<ivy:resolve/>
<ivy:report todir="${build.dir}/ivy-report" graph="false"/>
<ivy:cachepath pathid="compile.path" conf="compile"/>
<ivy:cachepath pathid="runtime.path" conf="runtime"/>
<ivy:cachepath pathid="test.path" conf="test"/>
</target>
Run Code Online (Sandbox Code Playgroud)