Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unsetting Property in Ant and Removing Property in Ant using a condition

Tags:

java

ant

How do you unset a property in ant? so that is is completely removed as a property?

<condition property="proguard.config" value="proguard.cfg">
      <isset property="proguarded"/>
</condition>


 <condition property="proguard.config" value="">
      <not>
      <isset property="proguarded"/>
      </not>
</condition>

This would seem to work. However proguard runs even if there is such a property as proguard.config in existence. So how do I remove proguard.config as a property altogether conditionally? I know that if proguard sees that there is a proguard.config property at all in the .properties file it is going to run.

like image 252
Code Droid Avatar asked May 17 '12 22:05

Code Droid


1 Answers

The Ant manual Property Task states:

Properties are immutable: whoever sets a property first freezes it for the rest of the build; they are most definitely not variables.

That being said, there are a couple of workarounds:

  1. Local Task - A local property at a given scope "shadows" properties of the same name at higher scopes (especially useful within Macrodefs)

  2. Ant-Contrib Variable Task - Ant-Contrib offers flexibility, but it also adds a dependency and can sometimes tempt you to write procedural Ant code that may be better expressed in an Ant script or a custom Ant task


In your example above, if the property proguarded does not change during the execution of your Ant project, then there is no need to unset the property. For example, you could conditionally execute targets as follows:

<target name="proguarded-target" if="proguarded">
  ...
</target>

<target name="not-proguarded-target" unless="proguarded">
  ...
</target>
like image 185
Christopher Peisert Avatar answered Sep 19 '22 18:09

Christopher Peisert