## 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