可以通過將 project.name
屬性設置為要構建的項目的名稱而為不同的項目使用相同的目標,如清單 5 中所示。
清單 5. 構建一組項目
<target name="buildall"> <!-- Invoke the "buildproject" target for a project from the workspace --> <antcall target="buildproject"> <!-- Pass the name of the project to be built --> <param name="project.name" value="MyFirstProject" /> </antcall> <!-- Invoke the "buildproject" target to build another project --> <antcall target="buildproject"> <!-- The project name is different --> <param name="project.name" value="MySecondProject" /> </antcall> </target> |
有時候會忽略此步驟。為所發布的每個構建版本使用一個版本號的方法對跟蹤缺陷和新添加的功能非常有用。Ant 提供了一個簡單 buildnumber任務,可實現此目的。清單 6 顯示了根據需要記錄更多有關版本信息的另一種方法。
清單 6. 記錄構建信息
<target name="baseline" description="Record build information"> <!-- The name of the file that holds the build information. If no such file exists, a new one gets created. --> <propertyfile file="${destination.dir}/build.info"> <!-- Initial build number is 0001. Then, any subsequent build increments |