I am working on a ant build script to deploy jars. i.e. to just update the final/beta application jar in specified folder. Its checks if the deployed jar is already up-to-date. If yes, it skips running the target using unless flag.
Below is the snippet of targets
<property name="deploy-dir-final" location="C:\Deploy\final" />
<property name="deploy-dir-beta" location="C:\Deploy\beta" />
<macrodef name="macro-deploy-jar">
<attribute name="deploydir" default="C:\Deploy\beta" />
<sequential>
<echo>Deploying jar</echo>
<copy overwrite="true" file="C:/project/application.jar" todir="@{deploydir}"/>
<echo>Deployed</echo>
</sequential>
</macrodef>
<target name="deploy-jar-final" depends="is-final-jar-up-to-date" unless="jar.isUpToDate">
<task-deploy-jar deploy-dir-path="${deploy-dir-final}"/>
</target>
<target name="deploy-jar-beta" depends="is-beta-jar-up-to-date" unless="jar.isBetaUpToDate">
<task-deploy-jar deploy-dir-path="${deploy-dir-beta}"/>
</target>
<target name="is-final-jar-up-to-date">
<echo message="Checking if deployed final jar is up-to-date"/>
<uptodate property="jar.isUpToDate" targetfile="${deploy-dir-final}/application.jar" >
<srcfiles dir= "${output-dir}" includes="application.jar"/>
</uptodate>
</target>
<target name="is-beta-jar-up-to-date">
<echo message="Checking if deployed beta jar is up-to-date"/>
<uptodate property="jar.isBetaUpToDate" targetfile="${deploy-dir-beta}/application.jar" >
<srcfiles dir= "${output-dir}" includes="application.jar"/>
</uptodate>
</target>
I have used macrodef for code reuse in case of deploy-jar targets. But before deploying I am checking if the existing jar is already up-to-date. Its done via depends attribute on targets. But I can see scope of code reuse here also as its only differ in paths. I did not get how we can pass parameters to depends targets.
Is there any way we can use something similar to macrodef for code reuse in this case? or can we use if condition on macordef so that it should only run if some property is set.
Or any other way I can achieve the same without having to write two targets to check final and beta jar, just to check if they are up-to-date.