ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Knuplesch, Jürgen <>
Subject AW: How to override a property that was set in the command line via "-D..."
Date Thu, 31 Jul 2014 10:15:54 GMT

because of the immutability of properties you have to redesign your scripts.
The first time you set a property is it. You are usually not able t change it later.
This is very important, because this is the only way to set properties from outside.

Why does your command line call then use "-D-DoutFileName=START", when you don’t want it?

Never do this, when you want to change the prop in your build.
If "START" is your default, then set it in the called target / Ant file, in your case "called.xml"

Its very important to understand why immutability is a feature and not a bug... (-;


-----Ursprüngliche Nachricht-----
Von: Al Le [] 
Gesendet: Donnerstag, 31. Juli 2014 11:10
Betreff: How to override a property that was set in the command line via "-D..."

How to override a property that was set in the command line via "-D..."


Could someone please help me with the following situation?

I have some ant scripts that are used in two ways:

1. Standalone build, i.e. the script is executed directly from the command line 2. As a part
of a larger build -- then the script is called via 'ant' from another
    script (here we have a main and a called scripts).

Each script uses a property 'outFileName' that specifies where to write some output to.
Both the main and the called script use this property. The script gets the value of the property
passed from the caller.

The root script (i.e. the one called from the command line) gets passed the value of 'outFileName'
via the "-DoutFileName=..." option.

When the main script calls a called script, it may specify another value for the property
'outFileName' (using the nested 'property' element). The called script should notice no difference
how it was called (i.e. whether it is called from the command line or as a called script from
another script).

Now the propblem: It turns out that the properties specified via "-D=..." are set as *user*
properties. Hence it's not possible to redefine them via the nested elements. Ant not even
using a script task with a call 'project.setProperty()'.

How would you solve this situation? I would not like introduce properties with a different
name, since my goal is to have scripts that can be 'customized' by specifying a property with
a well known name ('outFileName') -- be it on the command line or trough a nested element
of an ant task. Thik of it as of script interface.

The only possible solution I can think of is to specify a custom property helper, but that's
too much IMO and makes scripts not 'portable'.

Here's an example that I hope would explain the problem (I use ant 1.8.4 but I think the same
problem would also occur with ant 1.9.x):

-- Main build file 'main.xml' --

<project name="Main" default="run">
    <target name="run">
    	<echo>Main: outFileName: ${outFileName}</echo>
    	<ant antfile="called.xml" target="run">
    		<property name="outFileName" value="OTHER VALUE"/>

-- Called build file 'called.xml' --
<project name="Called" default="run">
    <target name="run">
    	<echo>Called: outFileName: ${outFileName}</echo>


-- Command line --
ant -f main.xml -DoutFileName=START

-- Actual output --
     [echo] Main: outFileName: START
     [echo] Called: outFileName: START

-- Expected (desired) output --
     [echo] Main: outFileName: START
     [echo] Called: outFileName: OTHER VALUE

Any help will be much appreciated.


To unsubscribe, e-mail: For additional commands, e-mail:

View raw message