- 在
<project>
里<target>
外定义的变量,该xml里的所有<target>
都可见这个变量,调用的别的xml里的<target>
也可见。 - 在
<target>
里定义的变量,跟这个<target>
无关的<target>
不可见这个变量,
把这个<target>
作为depends和被调用的<target>
可见这个变量。
例子:
运行mybuild1.xml,默认执行target: test,mybuild1.xml和mybuild2.xml文件里的target相互调用关系,
在这些target里的变量的作用域的可见范围见运行结果。
mybuild1.xml
<?xml version="1.0" encoding="UTF-8"?>
<project name="auto.all.ci" default="test" basedir="." xmlns:fl="antlib:it.haefelinger.flaka">
<taskdef resource="net/sf/antcontrib/antcontrib.properties">
<classpath>
<pathelement location="${ant.libs}/ant-contrib-0.6.jar" />
</classpath>
</taskdef>
<property name="varInProject" value="InProject"></property>
<target name="vars">
<property name="varInDependsTarget" value="InDepends"></property>
</target>
<target name="test" depends="vars">
<property name="varInParentTarget" value="InParentTarget"></property>
<antcall target="subTarget" />
<ant antfile="mybuild2.xml" target="subTarget1" >
<property name="varInNested" value="InNested"></property>
</ant>
</target>
<target name="noRelation">
<property name="varInNoRelationTarget" value="InNoRelationTarget"></property>
</target>
<target name="subTarget">
<echo>varInParentTarget:${varInParentTarget}</echo>
<echo>varInDependsTarget:${varInDependsTarget}</echo>
<echo>varInProject:${varInProject}</echo>
<echo>varInNoRelationTarget:${varInNoRelationTarget}</echo>
</target>
</project>
mybuild2.xml
<?xml version="1.0" encoding="UTF-8"?>
<project name="auto.all.ci" default="subTarget1" basedir="." xmlns:fl="antlib:it.haefelinger.flaka">
<taskdef resource="net/sf/antcontrib/antcontrib.properties">
<classpath>
<pathelement location="${ant.libs}/ant-contrib-0.6.jar" />
</classpath>
</taskdef>
<target name="subTarget1">
<echo>varInParentTarget:${varInParentTarget}</echo>
<echo>varInDependsTarget:${varInDependsTarget}</echo>
<echo>varInProject:${varInProject}</echo>
<echo>varInNested:${varInNested}</echo>
</target>
</project>
运行结果: