java - 使用目标覆盖时设置 ant 目标的顺序

标签 java ant

我正在重写从共享 build.xml 进行编译的调用,以在自定义构建中首先调用编译生成。

我使用depends="compile-generate,shared.compile"添加我的覆盖编译目标,如文档中所示和解释。但是,我的编译生成的目标现在被称为覆盖目标的第一个依赖项,而不是(因为我需要它是)最后一个依赖项。

有谁知道如何修复它,以便在调用编译目标时首先调用“shared.compile”的原始依赖项,最后调用我的重写依赖项?

我的build.xml:

<?xml version="1.0"?>
<project name="ExternalTools" basedir="." default="jar">

 <import file="../../../shared-build.xml" />

<target name="compile" depends="compile-generated, Shared.compile"/>
<target name="compile-generated">
        <mkdir dir="${classes.dir}"/>
        <javac srcdir="${src.gen.dir}"
         destdir="${classes.dir}"
         classpathref="build.classpath"
         debug="on"/>
</target>


</project>

共享“build.xml”编译目标:

<target name="compile" depends="prepare-staging-dirs,copy-dependlib-jars" description="Compile into stage directory">
                <javac srcdir="${src.dir}"
                       destdir="${classes.dir}"
                       classpathref="build.classpath"
                           includeantruntime="false"
                       debug="on"/>

                <copy todir="${classes.dir}">
                  <fileset dir="${src.dir}" includes="**/*.properties,**/*.xml,**/*.xsd,**/*.html" />
                </copy>
        </target>

最佳答案

依赖关系没有排序,而是分层的。如果同一层次结构中的两个依赖项以不期望的顺序运行,只需让一个依赖项依赖另一个即可。

就您而言,您可以告诉 compile- generated 依赖于您共享的 compile 依赖项。

在共享的 build.xml 中:

<target name="compile" depends="copy-dependlib-jars,prepare-staging-dirs">
    <echo message="Running root.compile" />
</target>

<target name="copy-dependlib-jars">
    <echo message="Running copy-dependlib-jars" />
</target>

<target name="prepare-staging-dirs">
    <echo message="Running prepare-staging-dirs" />
</target>

自定义 build.xml:

<import file="build.xml" />

<target name="compile" depends="compile-generated,root.compile">
    <echo message="Running custom compile" />
</target>

<target name="compile-generated" depends="copy-dependlib-jars,prepare-staging-dirs">
    <echo message="Running compile-generated" />
</target>

ant compile

 copy-dependlib-jars:
      [echo] Running copy-dependlib-jars

 prepare-staging-dirs:
      [echo] Running prepare-staging-dirs

 compile-generated:
      [echo] Running compile-generated

 root.compile:
      [echo] Running root.compile

 compile:
      [echo] Running custom compile

关于java - 使用目标覆盖时设置 ant 目标的顺序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48693821/

相关文章:

java - 使用 XML 配置生成 HTML 文件

java - 猜猜是谁?最佳算法

java - com.ibm.websphere.rsadapter.DB2UniversalDataStoreHelper 类需要哪个 jar 文件?

java - 从不同的类更改 TextView

java - 如何在 Apache POI Word 中添加图片交叉引用?

java - 类路径错误?为什么我仍然收到 NoClassDefFoundError?

Java:如何读取文件并获取值出现的次数?

java - ant java标签使用我自己的版本java.exe

php - 构建脚本是否在继续之前等待命令行任务完成?

java - Xmlbeans setter 在 gradle 测试中不起作用