Ant Ivy 不会设置编译类路径

Ant Ivy won't set compile classpath

我在网上读到的所有内容都说我这样做是对的,但是 Ant/Ivy 拒绝设置我的编译 class 路径。这是我的 ivy.xml:

<ivy-module version="2.0">
    <info organisation="com.latencyzero.missiondb" module="webapp"/>

    <configurations defaultconfmapping="runtime->*">
        <conf name="compile" visibility="public" description="this is the default scope, used if none is specified. Compile dependencies are available in all classpaths."/>
        <conf name="provided" visibility="public" description="this is much like compile, but indicates you expect the JDK or a container to provide it. It is only available on the compilation classpath, and is not transitive."/>
        <conf name="runtime" visibility="public" description="this scope indicates that the dependency is not required for compilation, but is for execution. It is in the runtime and test classpaths, but not the compile classpath." extends="compile"/>
        <conf name="test" visibility="private" description="this scope indicates that the dependency is not required for normal use of the application, and is only available for the test compilation and execution phases." extends="runtime"/>
    </configurations>

    <dependencies>
        <dependency org="org.apache.logging.log4j"              name="log4j"                        rev="2.13.3"            conf="compile->default"/>
    </dependencies>
</ivy-module>

以及build.xml的相关部分:

    <target name="resolve" description="==> retrieve dependencies with Ivy">
        <ivy:retrieve/>

        <ivy:cachepath pathid="compile.classpath" conf="compile" />
    </target>
    <target name="compile" depends="resolve" description="==> Compile Java sources">
        <mkdir  dir="${obj}"/>

        <javac  destdir="${obj}"
                source="${sourceVersion}"
                target="${targetClassVersion}"
                encoding="UTF-8"
                deprecation="${deprecation}"
                nowarn="${suppressWarnings}"
                debug="on"
                listfiles="false"
                includeantruntime="false">
            <classpath refid="compile.classpath"/>

            <src path="${common}"/>
            <src path="${src}"/>
        </javac>
    </target>

当我 运行 ant -v compile 时,它下载 log4j.jar 文件,然后忽略它:

[ivy:retrieve] :: Apache Ivy 2.4.0 - 20141213170938 :: http://ant.apache.org/ivy/ ::
...
[ivy:retrieve] main: module revision found in cache: org.apache.logging.log4j#log4j;2.13.3
[ivy:retrieve]  found org.apache.logging.log4j#log4j;2.13.3 in public
...
    [javac] Compiling 94 source files to .../repo/branches/v1.0/target/object
    [javac] Using modern compiler
    [javac] Compilation arguments:
    [javac] '-deprecation'
    [javac] '-d'
    [javac] '.../repo/branches/v1.0/target/object'
    [javac] '-classpath'
    [javac] '.../repo/branches/v1.0/target/object'
    [javac] '-sourcepath'
    [javac] '.../repo/branches/v1.0/lib/common/src:.../repo/branches/v1.0/src/main/java'
    [javac] '-target'
    [javac] '1.7'
    [javac] '-encoding'
    [javac] 'UTF-8'
    [javac] '-g'
    [javac] '-source'
    [javac] '1.7'
    [javac] 
    [javac] Files to be compiled:
...
    [javac] ...dao/AbstractDAOHibernate.java:23: error: package org.apache.logging.log4j does not exist
    [javac] import org.apache.logging.log4j.Logger;
    [javac]                                ^

注意 classpath 只有目标目录,没有 jars。我一定是遗漏了一些明显的东西,但我确实看不到它。

所以,事实证明我应该指定的依赖项是:

<dependency org="org.apache.logging.log4j" name="log4j-api" rev="2.13.3">
    <exclude module="log4j-api-java9"/>
</dependency>

而且我需要那里的 exclude 否则 Ivy 无法尝试下载不存在的模块。

在传递依赖方面,Ivy 似乎也有问题,所以我放弃了它,转而使用 Maven。