gpt4 book ai didi

ant - 嵌套子属性覆盖行为的解决方法(自 1.8.0 起)

转载 作者:行者123 更新时间:2023-12-04 21:22:42 24 4
gpt4 key购买 nike

我通过以下方式使用 apache ant:

我有项目 P1、P2、P3。其中一些项目有模块,比如说 P2 有 M1、M2 等。
所有项目都有自己的 ant 构建脚本,它们都必须实现一组预定义的目标(build、dist 等),这些脚本需要在调用时定义一些属性。假设(build.dir.base)

模块遵循类似的结构,因此每个模块都有自己的构建文件,该文件实现了预定义的目标集,并期望设置一些属性。 (假设 build.dir.base - 与项目相同)

我还有一个构建所有项目(或子集)的全局 ant 脚本

在看起来像这样的代码中:

构建-all.xml:

<project name="x">
<property name="build.dir.base" location="system.build.base" />
<target name="build">
<echo message="build.dir.base as defined for build-all.xml=${build.dir.base}" />
<subant antfile="build.xml" target="build" inheritAll="false" inheritRefs="false">
<dirset dir="${system.base}" includes="${project-list}" />
<property name="build.dir.base" location="${build.dir.base}" />
</subant>
</target>
</project>

build.xml(每个带有模块的项目一个,如果项目没有模块,则没有 subant):
<project name="y">
<property name="build.dir" location="${basedir}/build" />
<target name="build">
<echo message="build.dir.base as defined for project=${build.dir.base}" />
<subant antfile="build.xml" target="build" inheritAll="false" inheritRefs="false">
<dirset dir="project.base" includes="${module-list}" />
<property name="build.dir.base" location="${build.dir.base}/${name}" />
</subant>
</target>
</project>

对于具有模块的项目:
build.xml(对于一个模块):
<project name="z">
<property name="build.dir.base" location="build.dir.base" />
<target name="build">
<echo message="build.dir.base as defined for module=${build.dir.base}" />
</target>
</project>

这种结构允许独立构建项目,也可以独立构建模块或使用 build-all.xml 构建整个系统。
此外,最终产品具有以下结构:
  • ${system.build.base}/P1,
  • ${system.build.base}/P2/M1
  • ${system.build.base}/P2/M2

  • ETC

    但是,由于 ant >= 1.8.0 这不再可能。原因是 <property name="build.dir.base" location="${basedir}/build" />在 build-all.xml
    优先于 <property name="build.dir.base" location="${build.dir.base}/${name}" />在 build.xml(为项目构建)。因此,项目“子模块”的目的地是 ${system.build.base}/M1而不是 ${system.build.base}/P2/M1
    这是解释 Properties defined on the command line cannot be overridden by nested elements. Since Ant 1.8.0. the same is true for nested structures of tasks: if a build file A invokes B via an task setting a property with a nested element and B contains an tasks invoking C, C will see the value set in A, even if B used a nested element as well.

    无法覆盖 subant 的属性如果某些 parent 也定义了该属性。这很严重,因为构建应该知道父级出于某些不相关原因使用的属性。

    这种不兼容的行为变化是否有解决方法?因为,我的构建系统严重依赖于 <subant inheritAll="false" inheritRefs="false">将在不污染子构建的情况下执行 exec。

    最佳答案

    https://issues.apache.org/bugzilla/show_bug.cgi?id=49891似乎也与这个问题有关。

    在尝试了许多不同的事情(包括过滤掉不需要的属性然后重置它的技术)之后,我得出结论,在子任务中覆盖命令行属性是不可能的。

    关于ant - 嵌套子属性覆盖行为的解决方法(自 1.8.0 起),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9337295/

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