不同构建的多个 属性 文件

Multiple property files for different builds

我有一个项目有 3 个针对不同构建变体的目标,每个变体都有自己的 属性 文件,定义如下:

<target name="dev">
  <property file="dev.properties" />
  <antcall target="build" />
</target>

<target name="test">
  <property file="test.properties" />
  <antcall target="build" />
</target>

<target name="prod">
  <property file="prod.properties" />
  <antcall target="build" />
</target>

所有 属性 文件定义相同的属性。现在我需要制作一个可以构建它们的目标,我尝试了类似的方法:

<target name="all">
     <antcall target="dev" />
     <antcall target="test" />
     <antcall target="prod" />
</target>

但问题是 ant 属性是不可变的,我最终得到了所有构建的 dev.properties 属性。如果我想用自己的属性构建所有三个目标,推荐的方法是什么?

如果只有一个构建脚本,然后在 运行 时决定它的用途,会不会简单得多?

例如:

ant -propertyfile build-dev.properties
ant -propertyfile build-test.properties
ant -propertyfile build-prod.properties
..

这种方法在使用 Jenkins 等工具自动化构建时更加灵活。如果需要的话,它可以自动(并并行)检测源代码更改和 运行 每种构建类型。