views:

98

answers:

1

I want to delete the directory if the property "delete-compiled-dir" is set to true. If the property is false then do not execute it. Right now I have

<target name="deleted-after-compilation" depends="compile,jar">
        <condition property="${delete-compiled-dir}" value="true">
            <delete dir="${compilation-dir}" />
        </condition>
            <echo> Deleting Compiled Directory Classes </echo>
    </target>

I get the error message :

condition doesn't support the nested "delete" element.
+2  A: 

You can add the condition to your target using if (see manual).

The target will only be executed when the property compilation-dir is set (to any value, e.g. false).

<target name="deleted-after-compilation" depends="compile,jar"
        if="${compilation-dir}">
    <delete dir="${compilation-dir}" />
    <echo> Deleting Compiled Directory Classes </echo>
</target>

To only execute it when a property is set to true, you need to set another property first and check this one in the if. You could add both as dependency the another target:

<target name="set-delete-property">
    <condition property="delete-compilation-dir">
        <istrue value="${compilation-dir}"/>
    </condition>
</target>

<target name="deleted-after-compilation"
      depends="compile,jar" if="${compilation-dir}">
    ....

<target name="some-target"
      depends="set-delete-property,deleted-after-compilation">
</target>
Peter Lang
I don't want it to execute if the the property is false.
kunjaan
@kunjaan: Please see my updated answer
Peter Lang
(I can't test it at the moment, but it should work like that)
Peter Lang