user@ant.apache.org How to override a property that was set in the command line via "-D..."
Hello. 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"/> </ant> </target> </project> -- Called build file 'called.xml' -- <project name="Called" default="run"> <target name="run"> <echo>Called: outFileName: ${outFileName}</echo> </target> </project> -- Command line -- ant -f main.xml -DoutFileName=START -- Actual output -- run: [echo] Main: outFileName: START run: [echo] Called: outFileName: START -- Expected (desired) output -- run: [echo] Main: outFileName: START run: [echo] Called: outFileName: OTHER VALUE Any help will be much appreciated. Al --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscr...@ant.apache.org For additional commands, e-mail: user-h...@ant.apache.org