代码之家  ›  专栏  ›  技术社区  ›  Mark Aquino

使用目标重写时设置ant目标的顺序

  •  1
  • Mark Aquino  · 技术社区  · 6 年前

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

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

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

    我的身材。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>
    
    1 回复  |  直到 6 年前
        1
  •  0
  •   CAustin    6 年前

    依赖关系不是有序的,它们是分层的。如果同一层次结构中的两个依赖项以不需要的顺序运行,只需让一个依赖于另一个即可。

    在你的情况下,你可以说 compile-generated 依靠您的共享 compile 的依赖项。

    在共享生成中。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>
    

    自定义生成。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编译

     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