0

我正在使用 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由容器提供

提供执行我获得

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

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

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

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

4

2 回答 2

0

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

<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任务对于定期运行并确保您的构建是新鲜的很有用。

常春藤报告对于正确理解传递依赖关系也非常有用。

<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>
于 2013-05-15T21:32:55.097 回答
0

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

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

有关依赖项配置的更多文档:

于 2013-05-15T21:37:29.420 回答