gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-04 10:43:23 25 4
gpt4 key购买 nike

我正在重写从共享 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com