【问题标题】:Ivy, what is the master configuration and why is it not pulling jvyaml?ivy,主配置是什么,为什么不拉jvyaml?
【发布时间】:2012-07-10 16:00:27
【问题描述】:

我有以下常春藤文件:

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

我有一个 ant 检索任务,如下所示:

<target name="retrieve-all" depends="resolve">
    <ivy:retrieve pattern="lib/[conf]/[artifact]-[revision].[ext]" conf="*" />
</target>

奇怪的是,所有的 solr 依赖项都下载到 lib/runtime 中,但 jvyaml 模块却没有!它“解决”,但不会下载到 lib/runtime 目录,除非我将依赖项声明更改为:

<dependency org="net.java.dev" name="jvyaml" rev="0.2.1" conf="runtime->master" />

这个主配置是什么,为什么需要拉 jvyaml jar,而不是 solr?

谢谢

【问题讨论】:

    标签: ant ivy


    【解决方案1】:

    我建议按如下方式重构您的配置:

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

    引入的重要更改:

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

    配置映射解释

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

    在声明依赖项时,最好始终使用配置映射,以便毫无疑问地分配依赖项工件的位置。

    例如:

    <dependency org="??" name="??" rev="??" conf="runtime->default" />
    

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

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

    • 默认:远程模块的工件及其所有运行时传递依赖项
    • ma​​ster:仅远程模块的工件(无传递依赖)

    总之,我认为你的问题是由于远程 Maven 模块的“运行时”范围不包括 Maven 模块的工件,而是你得到了模块 jvyaml 不存在的传递依赖关系:-(

    p>

    一些额外的建议

    我还建议生成一个 ivy 依赖管理报告,如下所示:

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

    该报告将帮助解释每个依赖项如何最终出现在不同的配置上。对于确定如何管理传递依赖项也非常有用。

    最后,这里是配置继承得到回报的地方,创建了 ivy 托管的 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>
    

    【讨论】:

    【解决方案2】:

    请注意,原始 solr-core 也未检索到。 解决后,转到缓存并检查两个模块的 ivy.xml 文件。

    您将看到他们仅在 conf=master 中发布其工件

    <artifact name="jvyaml" type="jar" ext="jar" conf="master"/>
    
    <artifact name="solr-core" type="jar" ext="jar" conf="master"/>
    

    这意味着,您必须进行显式配置映射以表明您的内置配置应该唤起您的依赖项的“主”配置。 (检查配置映射)。

    但是,solr-core 的依赖项具有配置映射,您可以在 ivy.xml 文件中看到:

    <dependency org="org.apache.solr" name="solr-solrj" rev="3.6.0" force="true" conf="compile->compile(*),master(*);runtime->runtime(*)"/>
    

    我认为这是 master(*) 的东西。

    当我声明依赖项时,我通常会在自己的 ivy.xml 文件中进行映射:

      <dependency org="net.java.dev" name="jvyaml" rev="0.2.1" conf="runtime->master" />
    

    这表示运行时调用指定依赖项中的主配置。

    你可以这样做

    conf="runtime,test->master"
    

    还有

    【讨论】:

      猜你喜欢
      • 2010-12-07
      • 2014-09-16
      • 2013-01-04
      • 1970-01-01
      • 1970-01-01
      • 2015-04-12
      • 2013-02-12
      • 1970-01-01
      • 2015-02-08
      相关资源
      最近更新 更多