<p>We have an Apache ANT script to build our application, then check in the resulting JAR file into version control (VSS in this case).  However, now we have a change that requires us to build 2 JAR files for this project, then check both into VSS.</p>

<p>The current target that checks the original JAR file into VSS discovers the name of the JAR file through some property.  Is there an easy way to "generalize" this target so that I can reuse it to check in a JAR file with any name?  In a normal language this would obviously call for a function parameter but, to my knowledge, there really isn't an equivalent concept in ANT.</p>

[{'answer_id': 49920, 'author': 'Chris Dail', 'author_id': 5077, 'author_profile': 'https://Stackoverflow.com/users/5077', 'pm_score': 4, 'selected': False, 'text': '<p>It is generally considered a bad idea to version control your binaries and I do not recommend doing so. But if you absolutely have to, you can use antcall combined with param to pass parameters and call a target.</p>\n\n<pre><code>&lt;antcall target="reusable"&gt;\n    &lt;param name="some.variable" value="var1"/&gt;\n&lt;/antcall&gt;\n\n&lt;target name="reusable"&gt;\n    &lt;!-- Do something with ${some.variable} --&gt;\n&lt;/target&gt;\n</code></pre>\n\n<p>You can find more information about the <a href="http://ant.apache.org/manual/Tasks/antcall.html" rel="noreferrer">antcall task here</a>.</p>\n'}, {'answer_id': 49935, 'author': 'jodonnell', 'author_id': 4223, 'author_profile': 'https://Stackoverflow.com/users/4223', 'pm_score': 2, 'selected': False, 'text': '<p>Also check out the subant task, which lets you call the same target on multiple build files:</p>\n\n<pre><code>&lt;project name="subant" default="subant1"&gt;\n    &lt;property name="build.dir" value="subant.build"/&gt;\n    &lt;target name="subant1"&gt;\n        &lt;subant target=""&gt;\n            &lt;property name="build.dir" value="subant1.build"/&gt;\n            &lt;property name="not.overloaded" value="not.overloaded"/&gt;\n            &lt;fileset dir="." includes="*/build.xml"/&gt;\n        &lt;/subant&gt;\n    &lt;/target&gt;\n&lt;/project&gt;\n</code></pre>\n'}, {'answer_id': 50004, 'author': 'Dan Dyer', 'author_id': 5171, 'author_profile': 'https://Stackoverflow.com/users/5171', 'pm_score': 3, 'selected': False, 'text': '<p>Take a look at Ant <a href="http://ant.apache.org/manual/Tasks/macrodef.html" rel="noreferrer">macros</a>.  They allow you to define reusable "routines" for Ant builds.  You can find an example <a href="http://blog.uncommons.org/2007/10/25/15-tips-for-better-ant-builds/" rel="noreferrer">here</a> (item 15).</p>\n'}, {'answer_id': 65947, 'author': 'Vladimir', 'author_id': 9641, 'author_profile': 'https://Stackoverflow.com/users/9641', 'pm_score': 7, 'selected': True, 'text': '<p>I would suggest to work with <a href="http://ant.apache.org/manual/Tasks/macrodef.html" rel="nofollow noreferrer">macros</a> over subant/antcall because the main advantage I found with macros is that you\'re in complete control over the properties that are passed to the macro (especially if you want to add new properties).</p>\n\n<p>You simply refactor your Ant script starting with your target:</p>\n\n<pre><code>&lt;target name="vss.check"&gt;\n    &lt;vssadd localpath="D:\\build\\build.00012.zip" \n        comment="Added by automatic build"/&gt;\n&lt;/target&gt;\n</code></pre>\n\n<p>creating a macro (notice the copy/paste and replacement with the @{file}):</p>\n\n<pre><code>&lt;macrodef name="private-vssadd"&gt;\n    &lt;attribute name="file"/&gt;\n    &lt;sequential&gt;\n        &lt;vssadd localpath="@{file}" \n            comment="Added by automatic build"/&gt;\n    &lt;/sequential&gt;\n&lt;/macrodef&gt;\n</code></pre>\n\n<p>and invoke the macros with your files:</p>\n\n<pre><code>&lt;target name="vss.check"&gt;\n    &lt;private-vssadd file="D:\\build\\File1.zip"/&gt;\n    &lt;private-vssadd file="D:\\build\\File2.zip"/&gt;\n&lt;/target&gt;\n</code></pre>\n\n<p>Refactoring, "the Ant way"</p>\n'}, {'answer_id': 90722, 'author': 'Peter Kelley', 'author_id': 14893, 'author_profile': 'https://Stackoverflow.com/users/14893', 'pm_score': 1, 'selected': False, 'text': '<p>You can use <a href="http://gant.codehaus.org/" rel="nofollow noreferrer">Gant</a> to script your build with <a href="http://groovy.codehaus.org" rel="nofollow noreferrer">groovy</a> to do what you want or have a look at the <a href="http://groovy.codehaus.org/The+groovy+Ant+Task" rel="nofollow noreferrer">groovy ant task</a>.</p>\n'}]
['https://Stackoverflow.com/questions/49900', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1471/']