So ... I have build.xml that loads property file from basedir.
Then, as the target I perform the following:
<var name="Var1" value="<property_from_**first**_loaded_property_file>" />
<var name="<property_from_**first**_loaded_property_file>" unset="true"/>
<property file="../<other directory>/<**second**_property_file>.properties" />
<var name="Var2" value="<property_from_**second**_loaded_property_file>"/>
The ceavat here is that both has same property name. It cannot be changed.
So, in the end, I should get the property like:
Var1=<property_from_**first**_loaded_property_file>
Var2=<property_from_**second**_loaded_property_file>
But instead - I am getting signs that property (Var1) from first properties file is not unset and then filled with new value from second properties file. The thing that ant-contribs unset should deal with :/ ... something like:
Var1 = Var2
Why I am not getting the expected result?
I think the issue is that even though you're loading the variable into an antcontrib var
, it's still an ant property
first, thus immutable.
I know you can't change the property files, but what kind of freedom do you have with the script itself? You can try to leverage the scoping rules and the antcallback
task to scope where the variables get loaded.
For example, the following achieves - albeit somewhat messily - what I think you're after:
<?xml version="1.0" encoding="utf-8"?>
<project name="Test" basedir=".">
<path id="ant.classpath">
<fileset dir="${basedir}">
<include name="ant-contrib_AP.jar"/>
</fileset>
</path>
<taskdef resource="net/sf/antcontrib/antcontrib.properties" classpathref="ant.classpath"/>
<target name="test">
<antcallback target="load-more-prop" return="Var2"/>
<loadproperties>
<file file="prop1.properties"/>
</loadproperties>
<property name="Var1" value="${var}" />
<echo>${Var1}</echo>
<echo>${Var2}</echo>
</target>
<target name="load-more-prop">
<loadproperties>
<file file="prop2.properties"/>
</loadproperties>
<property name="Var2" value="${var}" />
</target>
</project>
In my console I see:
Buildfile: C:\Users\mfelzani\workspace-junk\junk\build.xml
test:
load-more-prop:
[echo] 7
[echo] 1
BUILD SUCCESSFUL
Total time: 905 milliseconds
Which matches the values i set in prop1.properties and prop2.properties, respectively, for the var property.