Ant的属性与引用

有许多方法可以设定 Ant 属性,可以通过Ant任务使用属性.您可以直接在AntBuilder的实例设置属性。Ant的属性也可以作为一个可改变的Map.也可以使用Ant的任务属性,如下例所示:

例16.13.设置Ant属性

build.gradle

ant.buildDir = buildDir
ant.properties.buildDir = buildDir
ant.properties['buildDir'] = buildDir
ant.property(name: 'buildDir', location: buildDir)

build.xml

<echo>buildDir = ${buildDir}</echo>

许多任务会在执行时设置属性.下面有几种方法来获取属性值,可以直接从AntBuilder实例获得属性,如下所示,ant的属性仍然是作为一个map:

例16.14.获取Ant属性

build.xml

<property name="antProp" value="a property defined in an Ant build"/>

build.gradle

println ant.antProp
println ant.properties.antProp
println ant.properties['antProp']

设置一个ant引用的方法:

例16.15.设置一个Ant引用

build.gradle

ant.path(id: 'classpath', location: 'libs')
ant.references.classpath = ant.path(location: 'libs')
ant.references['classpath'] = ant.path(location: 'libs')

build.xml

<path refid="classpath"/>

获取Ant引用的方法:

例16.16.获取一个Ant引用

build.xml

<path id="antPath" location="libs"/>

build.gradle

println ant.references.antPath
println ant.references['antPath']

results matching ""

    No results matching ""