我想我不能“得到”Ant。我很难搞清楚如何实现重用和控制一系列目标的执行。请帮忙。
我需要构建脚本来创建两个版本:调试版本和生成版本。目前我正在使用antcall
来解决我对Ant的误解。
让我使用伪命令代码来描述我希望构建的方式:
//this is my entry point
function build-production-and-debug() =
prepare()
build-production()
build-debug()
cleanup()
function build-production() =
pre-process()
compile()
post-process()
package("production")
function build-debug() =
compile()
package("debug")
我怎么想用Ant来解决这个问题?
答案 0 :(得分:2)
也许你可以把你的蚂蚁代码给出更好的答案。 但一种方法是使用depends属性
<target name="prepare">
//do something to prepare
</target>
<target name="cleanup">
//do something to cleanup
</target>
<target name="build-production">
//build production
</target>
<target name="build-debug">
//build debug
</target>
<target name="build-production-debug" depends="prepare,build-production, build-debug, cleanup">
//do something or nothing
</target>
有了这个,你告诉ant,在执行“build-production-debug”目标之前,你想首先运行“depends”属性上列出的所有目标,然后按顺序执行。
答案 1 :(得分:1)
以下是我提出的概要,我仍在使用antcall
,但仅作为入口点以参数化我的构建。我的关键发现是在目标上使用if
条件来控制目标是否被执行,并指出其依赖链中的目标仍然执行。 condition
和isset
任务在某些地方也有所帮助。
<project>
<target name="-init">
</target>
<target name="-prod-preprocess" depends="-init" if="production">
</target>
<target name="-compile" depends="-prod-preprocess">
</target>
<target name="-package" depends="-compile">
</target>
<target name="build-prod">
<property name="production" value="true" />
<property name="package.dir" location="${production.package.location}"/>
<antcall target="-package" />
</target>
<target name="build-debug">
<property name="package.dir" location="${debug.package.location}"/>
<antcall target="-package" />
</target>
<target name="build-both">
<antcall target="build-debug" />
<antcall target="build-prod" />
</target>
</project>