Gradle Ant的屬性與引用

2020-07-24 16:02 更新

有許多方法可以設(shè)定 Ant 屬性,可以通過Ant任務(wù)使用屬性.您可以直接在AntBuilder的實例設(shè)置屬性。Ant的屬性也可以作為一個可改變的Map.也可以使用Ant的任務(wù)屬性,如下例所示:

例16.13.設(shè)置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>

許多任務(wù)會在執(zhí)行時設(shè)置屬性.下面有幾種方法來獲取屬性值,可以直接從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']

設(shè)置一個ant引用的方法:

例16.15.設(shè)置一個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']


以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號