-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
156 lines (147 loc) · 3.14 KB
/
build.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
//project description
description = 'The shared API for the application'
task hello <<{
println 'Hello World'
}
//task description
hello{
description = 'This is hello of the build group'
group = 'build'
}
task upper <<{
String someString = 'my_NaMe'
println "Original:"+someString
println "Upper case:"+someString.toUpperCase()
}
task count <<{
4.times {
println "$it"
}
}
//依赖
task intro(dependsOn: hello) <<{
println "I'm Gradle"
}
//依赖声明顺序不必先后
task taskX(dependsOn:'taskY')<<{
println 'taskX'
}
task taskY<<{
println 'taskY'
}
//动态创建任务
5.times{
counter ->
task "task$counter" <<{
println "I'm task number $counter"
}
}
//通过api通信
task0.dependsOn task2,task3
//利用AntBuilder执行ant.loadfile
task loadfile << {
def files = file('../antLoadfileResources').listFiles().sort()
files.each { File file ->
if (file.isFile()) {
ant.loadfile(srcFile: file, property: file.name)
println " *** $file.name ***"
println "${ant.properties[file.name]}"
}
}
}
//利用方法组织脚本逻辑
task checksum << {
fileList('../antLoadfileResources').each{File file ->
ant.checksum(file:file,property:"cs_$file.name")
println "$file.name Checksum:${ant.properties['cs_$file.name']}"
}
}
File[] fileList(String dir){
file(dir).listFiles({file -> file.isFile()} as FileFilter).sort()
}
//定义默认任务
defaultTasks 'clean','run'
task clean << {
println 'Default Cleaning'
}
task run << {
println 'Default Running'
}
task other << {
println "I'm not a default task!"
}
//依赖任务的不同输出
task distribution << {
println "We build the zip with version=$version"
}
task release(dependsOn: 'distribution') << {
println 'We release now'
}
gradle.taskGraph.whenReady {taskGraph ->
if (taskGraph.hasTask(release)) {
version = '1.0'
} else {
version = '1.0-SNAPSHOT'
}
}
//依赖管理
apply plugin:'java'
repositories{
mavenCentral()
}
dependencies{
compile group :'org.hibernate',name:'hibernate-core',version:'3.6.7.Final'
testCompile group : 'junit',name:'junit',version:'4.+'
}
////publish produces lvy
//uploadArchves{
// repositories{
// try{
// credentials{
// username "username"
// password "pw"
// }
// url "http://repo,mycompany.com"
// }finally {
//
// }
// }
//}
////publish maven
//apply plugin:'maven'
//uploadArchives{
// repositories{
// mavenDeployer{
// repository(url:"file://localhost/tmp/myRepo/")
// }
// }
//}
//from another project's tasks
//project('projectA'){
// task taskX(dependsOn:':projectB:taskY') <<{
// println 'taskX'
// }
//}
//project('projectB'){
// task taskY << {
// println 'taskY'
// }
//}
//使用task对象添加依赖
taskY.dependsOn task0
//使用闭包添加依赖
task taskM << {
println 'taskM'
}
taskM.dependsOn{
tasks.findAll {task -> task.name.startsWith('lib')}
}
task lib1 << {
println 'lib1'
}
task lib2 << {
println 'lib2'
}
task notALib << {
println 'notALib'
}