常春藤,什么是主配置,为什么不拉jvyaml?

rai*_*inz 6 ant ivy

我有以下常春藤文件:

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

引入的重要变化:

  1. 使用更标准的"编译"配置
  2. 使用"extends"属性进行配置继承.然后,编译依赖项可以自动包含在运行时和测试配置中.
  3. 使用配置映射,例如:conf ="runtime-> default".这使得哪个本地配置与哪个远程配置相关联显而易见.

配置映射说明

配置是强大的常春藤功能.当ivy下载Maven模块时,它会执行内部翻译并分配一组标准配置,在此答案中列出:

在声明依赖项时,始终使用配置映射是个好主意,因此毫无疑问,依赖项工件的分配位置.

例如:

<dependency org="??" name="??" rev="??" conf="runtime->default" />
Run Code Online (Sandbox Code Playgroud)

这里我们说我们希望远程模块的默认依赖关系与我们的本地运行时配置相关联.

实际上,实际上只需要两个远程配置映射:

  • default:远程模块的工件及其所有的运行时传递依赖项
  • master:仅远程模块的工件(无传递依赖项)

总而言之,我认为您的问题是由于远程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)

  • 请用这个交换apache文档.谢谢@Mark (2认同)