## 1.設置ant屬性
build.xml:
~~~
<project>
<target name="hello">
<echo>buildDir=${buildDir}</echo>
</target>
</project>
~~~
我們要給buildDir屬性設值
~~~
ant.importBuild ('build.xml'){
antTargetName ->'a-'+antTargetName
}
task intro << {
println 'Hello,from gradle'
}
ant.buildDir = buildDir
ant.properties.buildDir = buildDir
ant.properties['buildDir'] = buildDir
ant.property(name:'buildDir',location:buildDir)
~~~
## 2.獲取ant屬性值
build.xml中定義屬性:
~~~
<project>
<property name="antProp" value="a property defined in an Ant build"/>
<target name="hello">
<echo>buildDir=${buildDir}</echo>
</target>
</project>
~~~
gradle.xml獲取屬性
~~~
ant.importBuild ('build.xml'){
antTargetName ->'a-'+antTargetName
}
task intro << {
println 'Hello,from gradle'
}
ant.buildDir = buildDir
ant.properties.buildDir = buildDir
ant.properties['buildDir'] = buildDir
ant.property(name:'buildDir',location:buildDir)
println ant.antProp
~~~
執行gradle命令,輸出如下:
~~~
qianhuis-Mac-mini:0112 qianhui$ gradle intro
a property defined in an Ant build
:intro
Hello,from gradle
BUILD SUCCESSFUL
Total time: 3.253 secs
~~~
## 3.設置reference的值
build.xml
~~~
<project>
<property name="antProp" value="a property defined in an Ant build"/>
<path refid="classpath"/>
<target name="hello">
<echo>buildDir=${buildDir}</echo>
</target>
</project>
~~~
最后三行是設置代碼
~~~
ant.importBuild ('build.xml'){
antTargetName ->'a-'+antTargetName
}
task intro << {
println 'Hello,from gradle'
}
ant.buildDir = buildDir
ant.properties.buildDir = buildDir
ant.properties['buildDir'] = buildDir
ant.property(name:'buildDir',location:buildDir)
println ant.antProp
ant.path(id:'classpath',location:'libs')
ant.references.classpath = ant.path(location:'libs')
ant.references['classpath'] = ant.path(location:'libs')
~~~
## 4.獲取reference的值
build.xml
~~~
<project>
<property name="antProp" value="a property defined in an Ant build"/>
<path refid="classpath"/>
<path id="antPath" location="libs"/>
<target name="hello">
<echo>buildDir=${buildDir}</echo>
</target>
</project>
~~~
build.gradle
~~~
ant.importBuild ('build.xml'){
antTargetName ->'a-'+antTargetName
}
task intro << {
println 'Hello,from gradle'
}
ant.buildDir = buildDir
ant.properties.buildDir = buildDir
ant.properties['buildDir'] = buildDir
ant.property(name:'buildDir',location:buildDir)
println ant.antProp
ant.path(id:'classpath',location:'libs')
ant.references.classpath = ant.path(location:'libs')
ant.references['classpath'] = ant.path(location:'libs')
println ant.references.antPath
println ant.references['antPath']
~~~
輸出如下:
~~~
qianhuis-Mac-mini:0112 qianhui$ gradle intro
a property defined in an Ant build
/Users/qianhui/Documents/Developer/gradle_project/0112/libs
/Users/qianhui/Documents/Developer/gradle_project/0112/libs
:intro
Hello,from gradle
BUILD SUCCESSFUL
Total time: 3.001 secs
~~~
- 前言
- gradle學習(1)-helloworld
- gradle學習(2)-基礎語法
- gradle學習(3)-基礎認識
- gradle學習(4)-構建java項目
- gradle學習(5)-創建eclipse項目
- gradle學習(6)-依賴管理
- gradle學習(7)-groovy
- gradle學習(8)-gradle的命令行
- gradle學習(9)-獲取build相關信息
- gradle學習(10)-gui
- gradle學習(11)-編寫構建腳本
- gradle學習(12)-groovy一些基礎語法
- gradle學習(13)-有的沒的
- gradle學習(14)-任務
- gradle學習(15)-任務
- gradle學習(16)-操作文件
- gradle學習(17)-被合并的ant
- gradle學習(18)-ant的屬性
- gradle學習(19)-log系統
- gradle學習(20)-詳解java插件
- gradle學習(21)-在eclipse中構建java項目
- gradle復習(1)-2種定義任務方式的區別
- gradle復習(2)-eclipse中添加依賴jar包
- gradle復習(3)-在gradle項目中使用TestNG
- gradle復習(4)-Cannot find System Java Compiler
- gradle復習(5)-Test remote debug
- gradle復習(6)-深入Jacoco
- gradle復習(7)-深入Jacoco
- gradle復習(8)-Task中行為
- gradle學習(22)-Sonar
- gradle學習(23)-Sonar runner