ant变量作用域

  1. <project><target>外定义的变量,该xml里的所有<target>都可见这个变量,调用的别的xml里的<target>也可见。
  2. <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>

运行结果:
这里写图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值