-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathutils.gradle
205 lines (191 loc) · 5.25 KB
/
utils.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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
/**
* 为哪个project添加哪些依赖
* @param project
* @param groups
*/
def implementations(Project project, Object... groups) {
for (Object dependence : groups) {
if (dependence instanceof Iterable) {
implementations(project, dependence)
}else if (dependence instanceof Map) {
implementations(project, dependence)
}else {
project.dependencies {
implementation dependence
}
}
}
}
def implementations(Project project, dependence) {
if (dependence instanceof Iterable) {
dependence.each {
implementations(project, it)
}
}else if (dependence instanceof Map) {
dependence.each {
implementations(project, it.value)
}
}else {
project.dependencies {
implementation dependence
}
}
}
def apis(Project project, dependence) {
if (dependence instanceof Iterable) {
dependence.each {
apis(project, it)
}
}else if (dependence instanceof Map) {
dependence.each {
apis(project, it.value)
}
}else {
project.dependencies {
api dependence
}
}
}
def apis(Project project, Object... groups) {
for (Object dependence : groups) {
if (dependence instanceof Iterable) {
apis(project, dependence)
}else if (dependence instanceof Map) {
apis(project, dependence)
}else {
project.dependencies {
api dependence
}
}
}
}
def annotationProcessors(Project project, dependence) {
if (dependence instanceof Iterable) {
dependence.each {
annotationProcessors(project, it)
}
}else if (dependence instanceof Map) {
dependence.each {
annotationProcessors(project, it.value)
}
}else {
project.dependencies {
annotationProcessor dependence
}
}
}
def annotationProcessors(Project project, Object... groups) {
for (Object dependence : groups) {
if (dependence instanceof Iterable) {
annotationProcessors(project, dependence)
}else if (dependence instanceof Map) {
annotationProcessors(project, dependence)
}else {
project.dependencies {
annotationProcessor dependence
}
}
}
}
def kapts(Project project, dependence) {
if (dependence instanceof Iterable) {
dependence.each {
kapts(project, it)
}
}else if (dependence instanceof Map) {
dependence.each {
kapts(project, it.value)
}
}else {
project.dependencies {
kapt (dependence) {
exclude module: "support-annotations"
exclude module: "annotation"
}
}
}
}
def kapts(Project project, Object... groups) {
for (Object dependence : groups) {
if (dependence instanceof Iterable) {
kapts(project, dependence)
}else if (dependence instanceof Map) {
kapts(project, dependence)
}else {
project.dependencies {
kapt (dependence) {
exclude module: "support-annotations"
exclude module: "annotation"
}
}
}
}
}
def addDep(Project project, Object key, Object dep) {
switch (key) {
case "implementation":
project.dependencies {
println("implementation:$dep")
implementation dep
}
break
case "compileOnly":
project.dependencies {
compileOnly dep
}
break
case "api":
project.dependencies {
api dep
}
break
case "annotationProcessor":
project.dependencies {
annotationProcessor dep
}
break
case "kapt":
project.dependencies {
println("kapt:$dep")
kapt dep
}
break
}
}
/**
* 依赖分组拓展方法
* @param project
* @param dependencies
* @return
*/
def deps(Project project, dependencies) {
def methods = ['implementation', 'compileOnly', 'annotationProcessor', 'kapt', 'api']
if (dependencies instanceof Map) {
dependencies.each {
if (methods.contains(it.key)) {
def value = it.value
if (value instanceof Map) {
value.each { dep ->
addDep(project, it.key, dep.value)
}
}else if (value instanceof Iterable) {
value.each { dep ->
addDep(project, it.key, dep)
}
}else if (value instanceof Object) {
addDep(project, it.key, value)
}
}else {
println("map:${it.key}=========")
deps(project, it.value)
}
}
}
}
ext {
implementations = this.&implementations
apis = this.&apis
annotationProcessors = this.&annotationProcessors
kapts = this.&kapts
deps = this.&deps
}