eastwater
eastwater

Reputation: 5542

How to conditionally include a zipfileset in Ant

In an Ant zip task, how can I include a zipfileset conditionally?

I have tried this:

<zip destfile="/path/bar.zip">
    <zipfileset src="foo.zip" if="include.foo.zip">
    </zipfileset>
    ...
</zip>

But zipfileset does not support if.

Upvotes: 1

Views: 607

Answers (1)

Wender
Wender

Reputation: 1001

You should include ant-contrib jar in Ant classpath and use the task def

<project name="MyProject" basedir="." default="build" xmlns:if="ant:if" xmlns:unless="ant:unless">
        <taskdef resource="net/sf/antcontrib/antcontrib.properties" />

        <target name="build">
            <echo file="salt">it's essential</echo>
            <echo file="chili">Not always</echo>

            <var name="canIncludeChili" value="false" />

            <zip destfile="meal.zip">
                <zipfileset prefix="meal" file="salt" />
                <zipfileset prefix="meal" file="chili" if:true="${canIncludeChili}" />
            </zip>
        </target>

    </project>

Upvotes: 1

Related Questions