1

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.

Peter Hall
  • 53,120
  • 14
  • 139
  • 204
eastwater
  • 4,624
  • 9
  • 49
  • 118

1 Answers1

1

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>
Wender
  • 991
  • 15
  • 24