A simple solution is to simply specify multiple sets of files in the same way that a javac task supports multiple src attributes:
<target name="build" depends="init" description="Create the package"> <javac destdir="${classes.dir}" includeantruntime="false"> <src path="src/main1/java"/> <src path="src/main2/java"/> </javac> <copy todir="${classes.dir}" includeemptydirs="false"> <fileset dir="src/main1" excludes="**/*.java"/> <fileset dir="src/main2" excludes="**/*.java"/> <flattenmapper/> </copy> </target>
This, of course, assumes that the number of places in the source code is fixed, which is not unreasonable to expect.
If you want to manage this using a list property, you must resort to embedding a script in your assembly to process this list (I cannot approve ant -contrib):
<project name="demo" default="build"> <property name="src.dirs" value="src/main1,src/main2"/> <property name="build.dir" location="build"/> <property name="classes.dir" location="${build.dir}/classes"/> <target name="bootstrap"> <mkdir dir="${user.home}/.ant/lib"/> <get dest="${user.home}/.ant/lib/groovy-all.jar" src="http://search.maven.org/remotecontent?filepath=org/codehaus/groovy/groovy-all/2.1.6/groovy-all-2.1.6.jar"/> </target> <target name="init"> <mkdir dir="${classes.dir}"/> </target> <target name="build" depends="init" description="Create the package"> <taskdef name="groovy" classname="org.codehaus.groovy.ant.Groovy"/> <groovy> def srcDirs = properties["src.dirs"].split(",") ant.javac(destdir:properties["classes.dir"], includeantruntime:false) { srcDirs.each { src(path:"${it}/java") } } ant.copy(todir:properties["classes.dir"], includeemptydirs:false) { srcDirs.each { fileset(dir:it, excludes:"**/*.java") } flattenmapper() } </groovy> </target> <target name="clean" description="Cleanup build dirs"> <delete dir="${build.dir}"/> </target> </project>
Notes:
- Compare build goals. You will notice that the groovy solution invokes ANT in the same way. That's why I really like groovy integration with ANT.
- The example also includes the goal of "bootstrap" to download jar groovy dependency on Maven Central . You can also use ivy to manage build dependencies.
Mark o'connor
source share