javaantparallel-buildsantcall

Preventing ant dependencies to be called multiple times in parallel


Background: I have a build process that compiles java code and builds two jars using the compiled classes (each jar a different subset, with some classes appearing in both).
Now, I was required that the users to be able to build each jar separately, but also be able to build them together in parallel (since it cuts the total build time by a lot).
So I came up with a script structured like this:

<project> 
    <target name="compile">
        <sequential>
            <echo message="compile"/>
        </sequential>
    </target>
    <target name="jar1" depends="compile">
        <sequential>
            <echo message="jar1"/>
        </sequential>
    </target>
    <target name="jar2" depends="compile">
        <sequential>
            <echo message="jar2"/>
        </sequential>
    </target>
    <target name="all-jars">
        <parallel>
            <antcall target="jar1"/>
            <antcall target="jar2"/>
        </parallel>
    </target>
</project>

The problem is that, when using the "all-jars" target, the "compile" target gets executed twice. Is there any standard way to prevent it? Better yet, is there an alternative to using antcall?

P.S. I found a similar question here but no answer was given.


Solution

  • Simply use unless property in the target "compile", as :

    ...
    <target name="compile" unless="compileDone">
        <property name="compileDone" value="true"/>
        <sequential>
            <echo message="compile"/>
        </sequential>
    </target>
    ...
    

    And your target will be executed only once :o)