【问题标题】:Apache Ivy and configurationsApache Ivy 和配置
【发布时间】:2013-05-10 06:57:11
【问题描述】:

我正在使用 Ivy 来管理我的依赖项,但在提供的 jar 上存在一些问题

这是我的 ivy.xml 文件

<configurations>
    <conf name="local" visibility="private" />
    <conf name="compile" description="used for building" />
    <conf name="test" extends="compile" description="used for testing" />
    <conf name="runtime" description="used for running" />
    <conf name="master" description="used for publishing" />
    <conf name="default" extends="master, runtime" />
</configurations>
<dependencies>
    <dependency org="xalan" name="xalan" rev="2.7.1"/>
    <dependency org="org.w3c.css" name="sac" rev="1.3"/>
    <dependency org="com.lowagie" name="itext" rev="2.0.8">
            <exclude org="bouncycastle"/>
    </dependency>
<!--Provided-->
<dependency org="javax.ejb" name="ejb-api" rev="3.0" conf="compile"/>
<dependency org="javax.jms" name="jms-api" rev="1.1-rev-1" conf="compile"/>
</dependencies>

ejb和jms由容器提供

Affer 执行我获得

---------------------------------------------------------------------
|                  |            modules            ||   artifacts   |
|       conf       | number| search|dwnlded|evicted|| number|dwnlded|
---------------------------------------------------------------------
|      compile     |   8   |   0   |   0   |   0   ||   6   |   0   |
|      default     |   6   |   0   |   0   |   0   ||   6   |   0   |
---------------------------------------------------------------------

所以 Ivy 的依赖关系很好,但是当我执行这个时

<ivy:cachepath pathid="normal.classpath" />
<pathconvert property="expanded.normal.classpath" refid="normal.classpath"/>
<echo message="${expanded.normal.classpath}" file="normal.classpath.txt"/>

<ivy:cachepath conf="compile" pathid="compile.classpath" />
<pathconvert property="expanded.compile.classpath" refid="compile.classpath"/>
<echo message="${expanded.compile.classpath}" file="compile.classpath.txt"/>

两个类路径相同。 有谁知道为什么?

【问题讨论】:

    标签: ivy dependency-management


    【解决方案1】:

    第一个ivy:cachepath 没有定义conf,它解析所有配置,所以每个模块都包含在内。

    第二个ivy:cachepath 只请求 conf 编译。所以声明为conf="compile"conf="compile-&gt;compile" 的同义词)的依赖项显然包括在内。并且没有任何conf属性的依赖也包括在内,因为默认的conf是*-&gt;*

    更多关于依赖配置的文档:

    【讨论】:

    • 谢谢。使用“运行时”设置其他依赖项后按预期工作。
    【解决方案2】:

    我建议减少配置数量并确保每个依赖项都有一个明确的映射。

    <ivy-module version="2.0">
      <info organisation="com.myspotontheweb" module="demo"/>
      <configurations>
        <conf name="compile" description="used for building"/>
        <conf name="runtime" description="used for running" extends="compile"/>
        <conf name="test"    description="used for testing" extends="runtime"/>
      </configurations>
      <dependencies>
        <!-- compile dependencies -->
        <dependency org="javax.ejb" name="ejb-api" rev="3.0" conf="compile->default"/>
        <dependency org="javax.jms" name="jms-api" rev="1.1-rev-1" conf="compile->default"/>
    
        <!-- runtime dependencies -->
        <dependency org="xalan" name="xalan" rev="2.7.1" conf="runtime->default"/>
        <dependency org="org.w3c.css" name="sac" rev="1.3" conf="runtime->default"/>
        <dependency org="com.lowagie" name="itext" rev="2.0.8" conf="runtime->default">
          <exclude org="bouncycastle"/>
        </dependency>
      </dependencies>
    </ivy-module>
    

    这将产生以下输出:

    ---------------------------------------------------------------------
    |                  |            modules            ||   artifacts   |
    |       conf       | number| search|dwnlded|evicted|| number|dwnlded|
    ---------------------------------------------------------------------
    |      compile     |   2   |   2   |   2   |   0   ||   2   |   2   |
    |      runtime     |   7   |   7   |   7   |   0   ||   7   |   7   |
    |       test       |   7   |   7   |   7   |   0   ||   7   |   7   |
    ---------------------------------------------------------------------
    

    演示如何在编译配置时只有 2 个 jars(如预期的那样)以及测试配置如何与运行时相同(预期是因为一个扩展了另一个)。 我发现在 ANT 构建构建中很少需要超过这 3 个不同的类路径。

    附加

    我注意到您的报告中没有下载任何内容。 cleancache 任务有助于定期运行并确保您的构建是最新的。

    report ivy 对于正确理解传递依赖关系也非常有用。

    <project name="demo" default="resolve" xmlns:ivy="antlib:org.apache.ivy.ant">
    
        <target name="resolve" description="Use ivy to resolve classpaths">
            <ivy:resolve/>
    
            <ivy:report todir='build/ivy' graph='false' xml='false'/>
    
            <ivy:cachepath pathid="compile.path" conf="compile"/>
            <ivy:cachepath pathid="test.path"    conf="test"/>
        </target>
    
        <target name="clean">
            <delete dir="build"/>
        </target>
    
        <target name="clean-all" depends="clean">
            <ivy:cleancache/>
        </target>
    
    </project>
    

    【讨论】:

      猜你喜欢
      • 2012-09-09
      • 2023-03-10
      • 2013-05-26
      • 2011-11-13
      • 2010-10-20
      • 2011-11-02
      • 2015-04-17
      • 2011-01-28
      • 2011-01-02
      相关资源
      最近更新 更多