简体   繁体   English

Ant Ivy 不会设置编译类路径

[英]Ant Ivy won't set compile classpath

Everything I've read online says I'm doing this right, but Ant/Ivy refuse to set my compile class path.我在网上阅读的所有内容都表明我做对了,但是 Ant/Ivy 拒绝设置我的编译 class 路径。 Here's my ivy.xml :这是我的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>

And the relevant portions of build.xml :以及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>

When I run ant -v compile , it downloads the log4j.jar file, and then ignores it:当我运行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]                                ^

Notice the classpath only has the target directory, and no jars.注意类路径只有目标目录,没有 jars。 I must be missing something obvious, but I sure can't see it.我一定遗漏了一些明显的东西,但我肯定看不到它。

So, it turns out the dependencies I should have specified were:因此,事实证明我应该指定的依赖项是:

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

And I need the exclude in there or Ivy fails trying to download a module that doesn't exist.而且我需要在那里exclude ,否则 Ivy 无法尝试下载不存在的模块。

It also seems that Ivy is buggy when it comes to transitive dependencies, so I gave up on it and switched to Maven.在传递依赖方面,Ivy 似乎也有问题,所以我放弃了它并切换到 Maven。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM