-
Notifications
You must be signed in to change notification settings - Fork 4.5k
/
ModuleDependencyExcludeResolveIntegrationTest.groovy
452 lines (403 loc) · 13.1 KB
/
ModuleDependencyExcludeResolveIntegrationTest.groovy
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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
/*
* Copyright 2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.gradle.integtests.resolve
import org.gradle.integtests.fixtures.executer.GradleContextualExecuter
import spock.lang.IgnoreIf
import spock.lang.Issue
import spock.lang.Unroll
/**
* Demonstrates the resolution of dependency excludes in published module metadata.
*/
@IgnoreIf({
// This test is very expensive. Ideally we shouldn't need an integration test here, but lack the
// infrastructure to simulate everything done here, so we're only going to execute this test in
// embedded mode
!GradleContextualExecuter.embedded
})
class ModuleDependencyExcludeResolveIntegrationTest extends AbstractModuleDependencyResolveTest {
def setup() {
buildFile << """
dependencies {
conf 'a:a:1.0'
}
task check(type: Sync) {
from configurations.conf
into 'libs'
}
"""
}
protected void succeedsDependencyResolution() {
succeeds 'check'
}
protected void assertResolvedFiles(List<String> files) {
file('libs').assertHasDescendants(files as String[])
}
/**
* Dependency exclude for a single artifact by using a combination of exclude rules.
*
* Dependency graph:
* a -> b, c
*/
def "dependency exclude that does not match transitive dependency is ignored"() {
given:
repository {
'a:a:1.0' {
dependsOn group: 'b', artifact: 'b', version: '1.0', exclusions: [excludeAttributes]
dependsOn 'c:c:1.0'
}
'b:b:1.0' {}
'c:c:1.0' {}
}
repositoryInteractions {
'a:a:1.0' {expectResolve()}
'b:b:1.0' {expectResolve()}
'c:c:1.0' {expectResolve()}
}
when:
succeeds "checkDep"
then:
resolve.expectGraph {
root(":", ":test:") {
module("a:a:1.0") {
module("b:b:1.0")
module("c:c:1.0")
}
}
}
where:
condition | excludeAttributes
'non-matching module' | [module: 'other']
'non-matching module' | [group: 'other']
'sibling module' | [module: 'c']
'sibling group' | [group: 'c']
'self module' | [module: 'b']
'self group' | [group: 'b']
}
/**
* Exclude of transitive dependency with a single artifact by using a combination of exclude rules.
*
* Dependency graph:
* a -> b, c
* b -> d
* c -> e
*
* Exclude is applied to dependency a->b
*/
@Unroll
def "dependency exclude for group or module applies to child module of dependency (#excluded)"() {
given:
def expectResolved = ['a', 'b', 'c', 'd', 'e'] - expectExcluded
repository {
'a:a:1.0' {
dependsOn group: 'b', artifact: 'b', version: '1.0', exclusions: [excludeAttributes]
dependsOn 'c:c:1.0'
}
'b:b:1.0' {
dependsOn 'd:d:1.0'
}
'c:c:1.0' {
dependsOn 'e:e:1.0'
}
'd:d:1.0'()
'e:e:1.0'()
}
repositoryInteractions {
expectResolved.each {
"${it}:${it}:1.0" { expectResolve() }
}
}
when:
succeedsDependencyResolution()
then:
def resolvedJars = expectResolved.collect { it + '-1.0.jar'}
assertResolvedFiles(resolvedJars)
where:
excluded | excludeAttributes | expectExcluded
'non-matching module' | [module: 'other'] | []
'non-matching group' | [group: 'other'] | []
'child name of sibling' | [module: 'e'] | []
'child group of sibling' | [group: 'e'] | []
'all child modules' | [module: '*'] | ['d']
'all child groups' | [group: '*'] | ['d']
'name child module' | [module: 'd'] | ['d']
'name child group' | [group: 'd'] | ['d']
}
/**
* Wildcard exclude of all transitive dependencies.
*
* Dependency graph:
* a -> b
* b -> c, d
*
* Wildcard exclude is applied to dependency a->b
*/
@Issue("https://issues.gradle.org/browse/GRADLE-3243")
def "wildcard exclude of group and module results in non-transitive dependency"() {
repository {
'a:a:1.0' {
dependsOn group: 'b', artifact: 'b', version: '1.0', exclusions: [[group: '*', module: '*']]
}
'b:b:1.0' {
dependsOn 'c:c:1.0'
dependsOn 'd:d:1.0'
}
'c:c:1.0'()
'd:d:1.0'()
}
repositoryInteractions {
'a:a:1.0' {expectResolve()}
'b:b:1.0' {expectResolve()}
}
when:
succeeds "checkDep"
then:
resolve.expectGraph {
root(":", ":test:") {
module("a:a:1.0") {
module("b:b:1.0")
}
}
}
}
/**
* Exclude of selected transitive dependencies.
*
* Dependency graph:
* a -> b
* b -> c, d
*
* Selective exclusions are applied to dependency a->b
*/
@Unroll
def "can exclude transitive dependencies (#condition)"() {
repository {
'a:a:1.0' {
dependsOn group: 'b', artifact: 'b', version: '1.0', exclusions: excludes
}
'b:b:1.0' {
dependsOn 'c:c:1.0'
dependsOn 'd:d:1.0'
}
'c:c:1.0'()
'd:d:1.0'()
}
repositoryInteractions {
expectResolved.each {
"${it}:${it}:1.0" { expectResolve() }
}
}
when:
succeedsDependencyResolution()
then:
def resolvedJars = expectResolved.collect { it + '-1.0.jar'}
assertResolvedFiles(resolvedJars)
where:
condition | excludes | expectResolved
'exclude c' | [[module: 'c']] | ['a', 'b', 'd']
'exclude d' | [[module: 'd']] | ['a', 'b', 'c']
'exclude both' | [[module: 'c'], [module: 'd']] | ['a', 'b']
'exclude neither' | [[module: 'other']] | ['a', 'b', 'c', 'd']
}
/**
* Exclude of transitive dependency involved in a dependency cycle.
*
* Dependency graph:
* a -> b -> c -> d -> c
*
* 'c' is excluded on dependency a->b
*/
def "can excluded module involved in dependency cycle"() {
given:
repository {
'a:a:1.0' {
dependsOn group: 'b', artifact: 'b', version: '1.0', exclusions: [[module: 'c']]
}
'b:b:1.0' {
dependsOn 'c:c:1.0'
}
'c:c:1.0' {
dependsOn 'd:d:1.0'
}
'd:d:1.0'() {
dependsOn 'c:c:1.0'
}
}
repositoryInteractions {
'a:a:1.0' { expectResolve() }
'b:b:1.0' { expectResolve() }
}
when:
succeeds "checkDep"
then:
resolve.expectGraph {
root(":", ":test:") {
module("a:a:1.0") {
module("b:b:1.0")
}
}
}
}
/**
* When a module artifact is depended on via multiple paths and excluded on one of those paths, it is not excluded.
*
* Dependency graph:
* a -> b, c
* b -> d
* c -> d
*/
def "when a module artifact is depended on via multiple paths it is only excluded if excluded on all paths"() {
given:
repository {
'a:a:1.0' {
dependsOn group: 'b', artifact: 'b', version: '1.0', exclusions: bExcludes
dependsOn group: 'c', artifact: 'c', version: '1.0', exclusions: cExcludes
}
'b:b:1.0' {
dependsOn 'd:d:1.0'
}
'c:c:1.0' {
dependsOn 'd:d:1.0'
}
'd:d:1.0'()
}
repositoryInteractions {
expectResolved.each {
"${it}:${it}:1.0" { expectResolve() }
}
}
when:
succeedsDependencyResolution()
then:
def resolvedJars = expectResolved.collect { it + '-1.0.jar'}
assertResolvedFiles(resolvedJars)
where:
condition | bExcludes | cExcludes | expectResolved
'excluded on b' | [[module: 'd']] | [] | ['a', 'b', 'c', 'd']
'excluded on c' | [] | [[module: 'd']] | ['a', 'b', 'c', 'd']
'excluded on both' | [[module: 'd']] | [[module: 'd']] | ['a', 'b', 'c']
}
/**
* When a module is depended on via a single chained path, it is excluded if excluded on any of the links in that path.
*
* Dependency graph:
* a -> b -> c -> d
*/
def "when a module is depended on via a single chained path, it is excluded if excluded on any of the links in that path (#name)"() {
given:
repository {
'a:a:1.0' {
dependsOn group: 'b', artifact: 'b', version: '1.0', exclusions: bExcludes
}
'b:b:1.0' {
dependsOn group: 'c', artifact: 'c', version: '1.0', exclusions: cExcludes
}
'c:c:1.0' {
dependsOn 'd:d:1.0'
}
'd:d:1.0'()
}
repositoryInteractions {
expectResolved.each {
"${it}:${it}:1.0" { expectResolve() }
}
}
when:
succeedsDependencyResolution()
then:
assertResolvedFiles(expectResolved.collect { it + '-1.0.jar'})
where:
condition | bExcludes | cExcludes | expectResolved
'excluded on b' | [[module: 'd']] | [] | ['a', 'b', 'c']
'excluded on c' | [] | [[module: 'd']] | ['a', 'b', 'c']
'excluded on both' | [[module: 'd']] | [[module: 'd']] | ['a', 'b', 'c']
'excluded on neither' | [] | [] | ['a', 'b', 'c', 'd']
}
def "excludes are retained in cached module metadata"() {
given:
repository {
'a:a:1.0' {
dependsOn group: 'b', artifact: 'b', version: '1.0', exclusions: [[module: 'c']]
}
'b:b:1.0' {
dependsOn 'c:c:1.0'
}
'c:c:1.0'()
}
repositoryInteractions {
'a:a:1.0' {expectResolve()}
'b:b:1.0' {expectResolve()}
}
and: // Initial request to cache metadata
succeeds "checkDeps"
when:
server.resetExpectations()
succeeds "checkDeps"
then:
resolve.expectGraph {
root(":", ":test:") {
module("a:a:1.0") {
module("b:b:1.0")
}
}
}
}
// this test documents current behavior; it is debatable if it is also the desired behavior
def "excludes of conflicting versions are merged"() {
given:
repository {
'a:a:1.0' {
dependsOn group: 'b', artifact: 'b', version: '1.0', exclusions: [[module: 'e']]
dependsOn 'c:c:1.0'
}
'c:c:1.0' {
dependsOn group: 'b', artifact: 'b', version: '2.0', exclusions: [[module: 'd'], [module: 'e']]
}
'b:b:1.0' {
dependsOn 'd:d:1.0'
dependsOn 'e:e:1.0'
}
'b:b:2.0' {
dependsOn 'd:d:1.0'
dependsOn 'e:e:1.0'
}
'd:d:1.0'()
'e:e:1.0'()
}
repositoryInteractions {
'a:a:1.0' { expectResolve() }
'b:b:1.0' { expectGetMetadata() }
'b:b:2.0' { expectResolve() }
'c:c:1.0' { expectResolve() }
'd:d:1.0' { expectResolve() }
}
when:
succeeds "checkDep"
then:
resolve.expectGraph {
root(":", ":test:") {
module("a:a:1.0") {
edge("b:b:1.0", "b:b:2.0")
module("c:c:1.0") {
module("b:b:2.0") {
// 'd' is NOT excluded, because the exclude in 'a:a:1.0 --depends-on--> b:b:1.0' only excludes 'e'
module("d:d:1.0")
}
}
}
}
}
}
}