-
Notifications
You must be signed in to change notification settings - Fork 89
/
Copy pathDependencyManagementPluginSpec.groovy
1294 lines (1198 loc) · 58.6 KB
/
DependencyManagementPluginSpec.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
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright 2014-2016 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 io.spring.gradle.dependencymanagement
import io.spring.gradle.dependencymanagement.internal.dsl.StandardDependencyManagementExtension
import org.gradle.api.Action
import org.gradle.api.GradleException
import org.gradle.api.InvalidUserDataException
import org.gradle.api.Project
import org.gradle.api.artifacts.DependencyResolveDetails
import org.gradle.testfixtures.ProjectBuilder
import spock.lang.Specification
public class DependencyManagementPluginSpec extends Specification {
Project project
def setup() {
project = new ProjectBuilder().build()
project.repositories {
mavenCentral()
}
}
def cleanup() {
project.projectDir.deleteDir()
}
def "Plugin provides the dependency management extension"() {
when: 'The plugin is applied'
project.apply plugin: 'io.spring.dependency-management'
then: 'The extension is available'
project.dependencyManagement
}
def "Plugin provides the dependency management report task"() {
when: 'The plugin is applied'
project.apply plugin: 'io.spring.dependency-management'
then: 'The report task is available'
project.tasks.getByName("dependencyManagement")
}
def "Customization of generated poms can be disabled"() {
given: 'A project with the plugin applied'
project.apply plugin: 'io.spring.dependency-management'
when: 'Published pom customization is disabled'
project.dependencyManagement {
generatedPomCustomization {
enabled = false
}
}
then: 'The configuration change has taken effect'
def extension = project.extensions.getByType(StandardDependencyManagementExtension)
!extension.pomCustomizationSettings.enabled
}
def "The pom configurer is available"() {
given: 'A project with the plugin applied'
project.apply plugin: 'io.spring.dependency-management'
expect: 'The pom configurer is available'
project.dependencyManagement.pomConfigurer
}
def "An imported bom can be used to apply dependency management"() {
given: 'A project that imports a bom'
project.apply plugin: 'io.spring.dependency-management'
project.apply plugin: 'java'
project.dependencyManagement {
imports {
mavenBom 'io.spring.platform:platform-bom:1.0.1.RELEASE'
}
}
project.dependencies {
compile 'org.springframework:spring-core'
}
when: 'A configuration is resolved'
def files = project.configurations.compile.resolve()
then: "The bom's dependency management has been applied"
files.size() == 1
files.collect { it.name }.containsAll(['spring-core-4.0.6.RELEASE.jar'])
}
def "An imported bom's versions can be overridden"() {
given: 'A project that overrides a version of an imported bom'
project.apply plugin: 'io.spring.dependency-management'
project.apply plugin: 'java'
project.ext['spring.version'] = '4.0.5.RELEASE'
project.dependencyManagement {
imports {
mavenBom 'io.spring.platform:platform-bom:1.0.1.RELEASE'
}
}
project.dependencies {
compile 'org.springframework:spring-core'
}
when: 'A configuration is resolved'
def files = project.configurations.compile.resolve()
then: 'Dependency management has been applied with the overridden version'
'4.0.5.RELEASE' == project.properties['spring.version']
files.size() == 1
files.collect { it.name }.containsAll(['spring-core-4.0.5.RELEASE.jar'])
}
def "Dependency management can be declared in the build"() {
given: 'A project with inline dependency management'
project.apply plugin: 'io.spring.dependency-management'
project.apply plugin: 'java'
project.dependencyManagement {
dependencies {
dependency 'org.springframework:spring-core:4.0.4.RELEASE'
dependency ('commons-logging:commons-logging:1.1.2') {
exclude 'foo:bar'
}
}
}
project.dependencies {
compile 'org.springframework:spring-core'
}
when: 'A configuration is resolved'
def files = project.configurations.compile.resolve()
then: 'Dependency management has been applied'
files.size() == 2
files.collect { it.name }
.containsAll(['spring-core-4.0.4.RELEASE.jar', 'commons-logging-1.1.2.jar'])
}
def "Dependency management can be declared in the build using the new syntax"() {
given: 'A project with the plugin applied'
project.apply plugin: 'io.spring.dependency-management'
project.apply plugin: 'java'
when: 'Dependency management is configured'
project.dependencyManagement {
dependencies {
dependency 'org.springframework:spring-core:4.0.4.RELEASE'
dependency('commons-logging:commons-logging:1.1.2') {
exclude 'foo:bar'
}
dependency group:'alpha', name: 'bravo', version: '1.0'
dependency(group:'charlie', name: 'delta', version: '2.0') {
exclude group:'bar', name:'baz'
}
}
}
then: 'The configuration has taken effect'
project.dependencyManagement
.managedVersions['org.springframework:spring-core'] == '4.0.4.RELEASE'
project.dependencyManagement
.managedVersions['commons-logging:commons-logging'] == '1.1.2'
project.dependencyManagement.managedVersions['alpha:bravo'] == '1.0'
project.dependencyManagement.managedVersions['charlie:delta'] == '2.0'
def exclusions = project.dependencyManagement.dependencyManagementContainer
.getExclusions(null)
exclusions.exclusionsForDependency('charlie:delta') as List == ['bar:baz']
exclusions.exclusionsForDependency('commons-logging:commons-logging') as List ==
['foo:bar']
}
def "Dependency management with exclusions can be declared in the build"() {
given: 'A project with inline dependency management'
project.apply plugin: 'io.spring.dependency-management'
project.apply plugin: 'java'
project.dependencyManagement {
dependencies {
dependency ('org.springframework:spring-core:4.0.4.RELEASE') {
exclude 'commons-logging:commons-logging'
}
}
}
project.dependencies {
compile 'org.springframework:spring-core'
}
when: 'A configuration is resolved'
def files = project.configurations.compile.resolve()
then: 'Dependency management and its exclusions has been applied'
files.size() == 1
files.collect { it.name }.containsAll(['spring-core-4.0.4.RELEASE.jar'])
}
def "Versions of direct dependencies take precedence over direct dependency management"() {
given: 'A project with a version on a direct dependency and dependency management for the dependency'
project.apply plugin: 'io.spring.dependency-management'
project.apply plugin: 'java'
project.dependencyManagement {
dependencies {
dependency 'org.springframework:spring-core:4.0.4.RELEASE'
}
}
project.dependencies {
compile 'org.springframework:spring-core:4.0.6.RELEASE'
}
when: 'A configuration is resolved'
def files = project.configurations.compile.resolve()
then: 'Dependency management is not applied to the versioned dependency'
files.size() == 2
files.collect { it.name }
.containsAll(['spring-core-4.0.6.RELEASE.jar', 'commons-logging-1.1.3.jar'])
}
def "Direct project dependencies take precedence over dependency management"() {
given: 'A project with a project dependency and dependency management for the dependency'
def child = new ProjectBuilder().withName('child').withParent(project).build()
child.group = 'test'
child.version = '1.1.0'
child.apply plugin: 'java'
project.apply plugin: 'io.spring.dependency-management'
project.apply plugin: 'java'
project.dependencyManagement {
dependencies {
dependency 'test:child:1.0.0'
}
}
project.dependencies {
compile project([path: ':child'])
}
when: 'A configuration is resolved'
def files = project.configurations.compile.resolve()
then: 'Dependency management is not applied to the project dependency'
files.size() == 1
files.collect { it.name }.containsAll(['child-1.1.0.jar'])
}
def "Transitive project dependencies take precedence over dependency management"() {
given: 'A project with a transitive project dependency and dependency management for the dependency'
def child = new ProjectBuilder().withName('child').withParent(project).build()
def grandchild = new ProjectBuilder().withName('grandchild').withParent(project).
build()
project.apply plugin: 'io.spring.dependency-management'
project.apply plugin: 'java'
grandchild.group = 'test-other'
grandchild.version = '1.1.0'
grandchild.apply plugin: 'java'
child.group = 'test'
child.version = '1.1.0'
child.apply plugin: 'java'
project.dependencyManagement {
dependencies {
dependency 'test:child:1.0.0'
dependency 'test-other:grandchild:1.0.0'
}
}
project.dependencies {
compile project([path: ':child'])
}
child.dependencies {
compile project([path: ':grandchild'])
}
when: 'A configuration is resolved'
def files = project.configurations.compile.resolve()
then: 'Dependency management is not applied to the project dependencies'
files.size() == 2
files.collect { it.name }.containsAll(['child-1.1.0.jar', 'grandchild-1.1.0.jar'])
}
def "Versions of direct dependencies take precedence over dependency management in an imported bom"() {
given: 'A project with a version on a direct dependency and imported dependency management for the dependency'
project.apply plugin: 'io.spring.dependency-management'
project.apply plugin: 'java'
project.dependencyManagement {
imports {
mavenBom 'io.spring.platform:platform-bom:1.0.1.RELEASE'
}
}
project.dependencies {
compile 'org.springframework:spring-core:4.0.4.RELEASE'
}
when: 'A configuration is resolved'
def files = project.configurations.compile.resolve()
then: 'Dependency management is not applied to the versioned dependency'
files.size() == 1
files.collect { it.name }.containsAll(['spring-core-4.0.4.RELEASE.jar'])
}
def "Dependency management can be applied to a specific configuration"() {
given: "A project with two configurations and dependency management for one of them"
project.apply plugin: 'io.spring.dependency-management'
project.apply plugin: 'java'
project.configurations {
managed
unmanaged
}
project.dependencyManagement {
managed {
dependencies {
dependency 'commons-logging:commons-logging:1.1.2'
}
}
}
project.dependencies {
managed 'org.springframework:spring-core:4.0.6.RELEASE'
unmanaged 'org.springframework:spring-core:4.0.6.RELEASE'
}
when: 'The configurations are resolved'
def managedFiles = project.configurations.managed.resolve()
def unmanagedFiles = project.configurations.unmanaged.resolve()
then: 'Dependency management is only applied to the managed configuration'
managedFiles.size() == 2
managedFiles.collect { it.name }
.containsAll(['spring-core-4.0.6.RELEASE.jar', 'commons-logging-1.1.2.jar'])
unmanagedFiles.size() == 2
unmanagedFiles.collect { it.name }
.containsAll(['spring-core-4.0.6.RELEASE.jar', 'commons-logging-1.1.3.jar'])
}
def "Dependency management can be applied to multiple specific configurations"() {
given: "A project with three configurations and dependency management for two of them"
project.apply plugin: 'io.spring.dependency-management'
project.apply plugin: 'java'
project.configurations {
managed1
managed2
unmanaged
}
project.dependencyManagement {
configurations(managed1, managed2) {
dependencies {
dependency 'commons-logging:commons-logging:1.1.2'
}
}
}
project.dependencies {
managed1 'org.springframework:spring-core:4.0.6.RELEASE'
managed2 'org.springframework:spring-core:4.0.6.RELEASE'
unmanaged 'org.springframework:spring-core:4.0.6.RELEASE'
}
when: 'The configurations are resolved'
def managed1Files = project.configurations.managed1.resolve()
def managed2Files = project.configurations.managed2.resolve()
def unmanagedFiles = project.configurations.unmanaged.resolve()
then: 'Dependency management is only applied to the managed configurations'
managed1Files.size() == 2
managed1Files.collect { it.name }
.containsAll(['spring-core-4.0.6.RELEASE.jar', 'commons-logging-1.1.2.jar'])
managed2Files.size() == 2
managed2Files.collect { it.name }
.containsAll(['spring-core-4.0.6.RELEASE.jar', 'commons-logging-1.1.2.jar'])
unmanagedFiles.size() == 2
unmanagedFiles.collect { it.name }
.containsAll(['spring-core-4.0.6.RELEASE.jar', 'commons-logging-1.1.3.jar'])
}
def "Configuration-specific dependency management takes precedence over global dependency management"() {
given: "A project with global and configuration-specific dependency management"
project.apply plugin: 'io.spring.dependency-management'
project.apply plugin: 'java'
project.dependencyManagement {
dependencies {
dependency 'commons-logging:commons-logging:1.1.2'
}
compile {
dependencies {
dependency 'commons-logging:commons-logging:1.1.1'
}
}
}
project.dependencies {
compile 'org.springframework:spring-core:4.0.6.RELEASE'
}
when: 'The configuration is resolved'
def files = project.configurations.compile.resolve()
then: 'The configuration-specific dependency management has taken precedence'
files.size() == 2
files.collect { it.name }
.containsAll(['spring-core-4.0.6.RELEASE.jar', 'commons-logging-1.1.1.jar'])
}
def "Configuration-specific dependency management is inherited by extending configurations"() {
given: "A project with global and configuration-specific dependency management"
project.apply plugin: 'io.spring.dependency-management'
project.apply plugin: 'java'
project.dependencyManagement {
compile {
dependencies {
dependency 'commons-logging:commons-logging:1.1.1'
}
}
}
project.dependencies {
testRuntime 'commons-logging:commons-logging'
}
when: 'The extending configuration is resolved'
def files = project.configurations.testRuntime.resolve()
then: 'The configuration-specific dependency management has been inherited'
files.size() == 1
files.collect { it.name }.containsAll(['commons-logging-1.1.1.jar'])
}
def "A version on a direct dependency provides dependency management to extending configurations"() {
given: "A project with global dependency management and a versioned dependency in the compile configuration"
project.apply plugin: 'io.spring.dependency-management'
project.apply plugin: 'java'
project.dependencyManagement {
dependencies {
dependency 'commons-logging:commons-logging:1.1.1'
}
}
project.dependencies {
compile 'commons-logging:commons-logging:1.1.3'
}
when: 'An extending configuration is resolved'
def files = project.configurations.testRuntime.resolve()
then: 'The dependency management provided by the direct dependency has been inherited'
files.size() == 1
files.collect { it.name }.containsAll(['commons-logging-1.1.3.jar'])
}
def "The JBoss Java EE bom can be imported and used for dependency management (see gh-3)"() {
given: 'A project that imports the JBoss bom'
project.apply plugin: 'io.spring.dependency-management'
project.apply plugin: 'java'
project.dependencyManagement {
imports {
mavenBom 'org.jboss.spec:jboss-javaee-6.0:1.0.0.Final'
}
}
project.dependencies {
compile 'org.jboss.spec.javax.el:jboss-el-api_2.2_spec'
}
when: 'A configuration is resolved'
def files = project.configurations.compile.resolve()
then: "The bom's dependency management has been applied"
files.size() == 1
files.iterator().next().name == 'jboss-el-api_2.2_spec-1.0.0.Final.jar'
}
def "A bom with no dependency management can be imported and its properties used (see gh-41)" () {
given: 'A project with the plugin applied'
project.apply plugin: 'io.spring.dependency-management'
project.apply plugin: 'java'
project.repositories {
maven {
url new File("src/test/resources/maven-repo").toURI().toURL().toString()
}
}
when: 'A bom with no dependency management is imported'
project.dependencyManagement {
imports {
mavenBom 'test:no-dependency-management-bom:1.0'
}
}
then: "The bom's bomProperties are available"
project.dependencyManagement.importedProperties['a'] == 'alpha'
}
def "The Spring Cloud Starter Parent bom can be imported and used for dependency management"() {
given: 'A project that imports the Spring Cloud Starter Parent bom'
project.apply plugin: 'io.spring.dependency-management'
project.apply plugin: 'java'
project.repositories {
maven { url 'https://repo.spring.io/libs-milestone' }
}
project.dependencyManagement {
imports {
mavenBom 'org.springframework.cloud:spring-cloud-starter-parent:1.0.0.M3'
}
}
expect: "The bom's versions are available"
project.dependencyManagement.compile
.managedVersions['org.springframework.cloud:spring-cloud-starter-eureka-server'] == '1.0.0.M3'
}
def 'A dependency set can be used to provide dependency management for multiple modules with the same group and version'() {
given: 'A project with dependency management that uses a dependency set'
project.apply plugin: 'io.spring.dependency-management'
project.apply plugin: 'java'
project.dependencyManagement {
dependencies {
dependencySet(group: 'org.slf4j', version: '1.7.7') {
entry 'slf4j-api'
entry 'slf4j-simple'
}
}
}
project.dependencies {
compile 'org.slf4j:slf4j-api'
compile 'org.slf4j:slf4j-simple'
}
when: 'The configuration is resolved'
def files = project.configurations.compile.resolve()
then: 'The dependency management has been applied'
files.size() == 2
files.collect { it.name }.containsAll(['slf4j-api-1.7.7.jar', 'slf4j-simple-1.7.7.jar'])
}
def 'An exclusion can be declared on an entry in a dependency set'() {
given: 'A project with dependency management that uses a dependency set'
project.apply plugin: 'io.spring.dependency-management'
project.apply plugin: 'java'
project.dependencyManagement {
dependencies {
dependencySet(group: 'org.springframework', version: '4.1.4.RELEASE') {
entry('spring-core') {
exclude 'commons-logging:commons-logging'
}
}
}
}
project.dependencies {
compile 'org.springframework:spring-core'
}
when: 'The configuration is resolved'
def files = project.configurations.compile.resolve()
then: 'The dependency management and its exclusions has been applied'
files.size() == 1
files.collect { it.name }.containsAll(['spring-core-4.1.4.RELEASE.jar'])
}
def 'Managed versions can be accessed programatically'() {
given: 'A project with the plugin applied'
project.apply plugin: 'io.spring.dependency-management'
project.apply plugin: 'java'
when: 'Dependency management is configured'
project.dependencyManagement {
imports {
mavenBom 'io.spring.platform:platform-bom:1.0.1.RELEASE'
}
testRuntime {
dependencies {
dependency 'com.foo:bar:1.2.3'
}
}
dependencies {
dependencySet(group: 'com.alpha', version: '1.0') {
entry 'bravo'
entry 'charlie'
}
}
}
then: 'The managed versions can be accessed'
project.dependencyManagement.compile
.managedVersions['org.springframework:spring-core'] == '4.0.6.RELEASE'
project.dependencyManagement.testRuntime
.managedVersions['org.springframework:spring-core'] == '4.0.6.RELEASE'
project.dependencyManagement
.managedVersions['org.springframework:spring-core'] == '4.0.6.RELEASE'
project.dependencyManagement.compile.managedVersions['com.foo:bar'] == null
project.dependencyManagement.testRuntime.managedVersions['com.foo:bar'] == '1.2.3'
project.dependencyManagement.managedVersions['com.foo:bar'] == null
project.dependencyManagement.compile.managedVersions['com.alpha:bravo'] == '1.0'
project.dependencyManagement.testRuntime.managedVersions['com.alpha:bravo'] == '1.0'
project.dependencyManagement.managedVersions['com.alpha:bravo'] == '1.0'
project.dependencyManagement.compile.managedVersions['com.alpha:charlie'] == '1.0'
project.dependencyManagement.testRuntime.managedVersions['com.alpha:charlie'] == '1.0'
project.dependencyManagement.managedVersions['com.alpha:charlie'] == '1.0'
}
def 'Properties imported from a bom can be accessed'() {
given: 'A project with the plugin applied'
project.apply plugin: 'io.spring.dependency-management'
project.apply plugin: 'java'
when: 'A bom is imported'
project.configurations {
myConfiguration
}
project.dependencyManagement {
imports {
mavenBom 'io.spring.platform:platform-bom:1.0.1.RELEASE'
}
myConfiguration {
imports {
mavenBom 'org.springframework.boot:spring-boot-dependencies:1.2.1.RELEASE'
}
}
}
then: 'The bomProperties in the bom can be accessed'
'4.3.5.Final' == project.dependencyManagement.importedProperties['hibernate.version']
'4.1.4.RELEASE' == project.dependencyManagement.myConfiguration
.importedProperties['spring.version']
'1.7.12' == project.dependencyManagement.myConfiguration.importedProperties['jruby.version']
}
def 'A bom property can be used to version a dependency'() {
given: 'A project that imports a bom'
project.apply plugin: 'io.spring.dependency-management'
project.apply plugin: 'java'
project.configurations {
myConfiguration
}
project.dependencyManagement {
imports {
mavenBom 'io.spring.platform:platform-bom:1.0.1.RELEASE'
}
}
when: 'A property is used to version a dependency that is not included in the bom'
project.dependencies {
myConfiguration "org.hibernate:hibernate-envers:${project.dependencyManagement.importedProperties['hibernate.version']}"
}
then: 'The dependency has the expected version'
def files = project.configurations.myConfiguration.resolve()
files.collect { it.name }.contains('hibernate-envers-4.3.5.Final.jar')
}
def 'Bom that references java home can be imported'() {
given: 'A project with the plugin applied'
project.apply plugin: 'io.spring.dependency-management'
project.apply plugin: 'java'
when: 'A bom that references java home is imported'
project.dependencyManagement {
imports {
mavenBom 'org.jboss:jboss-parent:11'
}
}
then: 'Its dependency management can be accessed'
project.dependencyManagement.managedVersions['com.sun:tools'] == '1.6'
}
def 'Dependency versions can be defined using properties'() {
given: 'A project with the plugin applied and a version property'
project.apply plugin: 'io.spring.dependency-management'
project.apply plugin: 'java'
project.ext['springVersion'] = '4.1.1.RELEASE'
project.ext['slf4jVersion'] = '1.7.7'
when: 'Dependency management that contains a dependency that references the property is declared'
project.dependencyManagement {
dependencies {
dependency "org.springframework:spring-core:$springVersion"
dependency "org.springframework:spring-beans:$springVersion"
dependency "org.springframework:spring-tx:${project.ext['springVersion']}"
dependencySet(group: 'org.slf4j', version: slf4jVersion) {
entry 'slf4j-api'
}
}
}
then: 'The expected version has been applied'
project.dependencyManagement
.managedVersions['org.springframework:spring-core'] == '4.1.1.RELEASE'
project.dependencyManagement
.managedVersions['org.springframework:spring-tx'] == '4.1.1.RELEASE'
project.dependencyManagement
.managedVersions['org.slf4j:slf4j-api'] == '1.7.7'
}
def 'The import of a bom can reference a property'() {
given: 'A project with the plugin applied and a version property'
project.apply plugin: 'io.spring.dependency-management'
project.apply plugin: 'java'
project.ext['platformVersion'] = '1.0.1.RELEASE'
when: 'Dependency management that imports a bom using a property for its version is declared'
project.dependencyManagement {
imports {
mavenBom "io.spring.platform:platform-bom:$platformVersion"
}
}
then: 'The dependency management from the bom has been applied'
project.dependencyManagement
.managedVersions['org.springframework:spring-core'] == '4.0.6.RELEASE'
}
def 'An explicit dependency prevents the dependency from being excluded'() {
given: 'A project that imports a bom'
project.apply plugin: 'io.spring.dependency-management'
project.apply plugin: 'java'
project.dependencyManagement {
imports {
mavenBom 'io.spring.platform:platform-bom:1.0.1.RELEASE'
}
}
project.dependencies {
compile 'org.springframework:spring-core'
compile 'commons-logging:commons-logging:1.1.3'
}
when: 'A configuration is resolved'
def files = project.configurations.compile.resolve()
then: "The bom's dependency management has been applied"
files.size() == 2
files.collect { it.name }
.containsAll(['spring-core-4.0.6.RELEASE.jar', 'commons-logging-1.1.3.jar'])
}
def 'A transitive dependency with an unexcluded path prevents exclusion'() {
given: 'A project that imports a bom'
project.apply plugin: 'io.spring.dependency-management'
project.apply plugin: 'java'
project.dependencyManagement {
imports {
mavenBom 'io.spring.platform:platform-bom:1.0.1.RELEASE'
}
}
project.dependencies {
compile 'org.springframework:spring-core'
compile 'org.apache.hive:hive-common:0.14.0'
}
when: 'A configuration is resolved'
def files = project.configurations.compile.resolve()
then: "The bom's dependency management has been applied"
files.collect { it.name }.
containsAll(['spring-core-4.0.6.RELEASE.jar', 'commons-logging-1.1.3.jar',
'hive-common-0.14.0.jar'])
}
def 'An exclusion declared on the dependency that has the excluded dependency is honoured'() {
given: 'A project with the plugin applied'
project.apply plugin: 'io.spring.dependency-management'
project.apply plugin: 'java'
project.repositories {
maven { url new File("src/test/resources/maven-repo").toURI().toURL().toString() }
}
when: 'It depends on a module that directly excludes commons-logging'
project.dependencies {
compile 'test:direct-exclude:1.0'
}
def files = project.configurations.compile.resolve()
then: "commons-logging has been excluded"
files.size() == 4
files.collect { it.name }.containsAll(['direct-exclude-1.0.jar',
'spring-tx-4.1.2.RELEASE.jar',
'spring-beans-4.1.2.RELEASE.jar',
'spring-core-4.1.2.RELEASE.jar'])
}
def 'A dependency with an otherwise excluded transitive dependency overrides the exclude'() {
given: 'A project with the plugin applied'
project.plugins.apply(DependencyManagementPlugin)
project.apply plugin: 'java'
project.repositories {
maven { url new File("src/test/resources/maven-repo").toURI().toURL().toString() }
}
when: 'It depends on a module that directly excludes commons-logging and one that does not'
project.dependencies {
compile 'test:direct-exclude:1.0'
compile 'org.springframework:spring-core:4.1.2.RELEASE'
}
def files = project.configurations.compile.resolve()
then: "commons-logging has not been excluded"
files.size() == 5
files.collect { it.name }.containsAll(['direct-exclude-1.0.jar',
'spring-tx-4.1.2.RELEASE.jar',
'spring-beans-4.1.2.RELEASE.jar',
'spring-core-4.1.2.RELEASE.jar'])
}
def 'An exclusion that applies transitively is honoured'() {
given: 'A project with the plugin applied'
project.apply plugin: 'io.spring.dependency-management'
project.apply plugin: 'java'
project.repositories {
maven { url new File("src/test/resources/maven-repo").toURI().toURL().toString() }
}
when: 'It depends on a module that transitively excludes commons-logging'
project.dependencies {
compile 'test:transitive-exclude:1.0'
}
def files = project.configurations.compile.resolve()
then: "commons-logging has been excluded"
files.size() == 4
files.collect { it.name }.containsAll(['transitive-exclude-1.0.jar',
'spring-tx-4.1.2.RELEASE.jar',
'spring-beans-4.1.2.RELEASE.jar',
'spring-core-4.1.2.RELEASE.jar'])
}
def 'A direct exclusion declared in a bom is honoured'() {
given: 'A project with the plugin applied'
project.apply plugin: 'io.spring.dependency-management'
project.apply plugin: 'java'
project.repositories {
maven { url new File("src/test/resources/maven-repo").toURI().toURL().toString() }
}
when: 'It imports a bom that directly excludes commons-logging'
project.dependencyManagement {
imports {
mavenBom 'test:direct-exclude-bom:1.0'
}
}
project.dependencies {
compile 'org.springframework:spring-tx:4.1.2.RELEASE'
}
def files = project.configurations.compile.resolve()
then: "commons-logging has been excluded"
files.size() == 3
files.collect { it.name }.containsAll(['spring-tx-4.1.2.RELEASE.jar',
'spring-beans-4.1.2.RELEASE.jar',
'spring-core-4.1.2.RELEASE.jar'])
}
def 'A transitive exclusion declared in a bom is honoured'() {
given: 'A project with the plugin applied'
project.apply plugin: 'io.spring.dependency-management'
project.apply plugin: 'java'
project.repositories {
maven { url new File("src/test/resources/maven-repo").toURI().toURL().toString() }
}
when: 'It imports a bom that transitively excludes commons-logging'
project.dependencyManagement {
imports {
mavenBom 'test:transitive-exclude-bom:1.0'
}
}
project.dependencies {
compile 'org.springframework:spring-tx:4.1.2.RELEASE'
}
def files = project.configurations.compile.resolve()
then: "commons-logging has been excluded"
files.size() == 3
files.collect { it.name }.containsAll(['spring-tx-4.1.2.RELEASE.jar',
'spring-beans-4.1.2.RELEASE.jar',
'spring-core-4.1.2.RELEASE.jar'])
}
def 'Exclusions are not inherited and do not affect direct dependencies (see gh-21)'() {
given: 'A project with the plugin applied'
project.apply plugin: 'io.spring.dependency-management'
project.apply plugin: 'java'
project.repositories {
maven { url new File("src/test/resources/maven-repo").toURI().toURL().toString() }
}
when: 'It depends on a module that excludes commons-logging in compile and on ' +
'commons-logging in testCompile'
project.dependencies {
compile 'test:direct-exclude:1.0'
testCompile 'commons-logging:commons-logging:1.1.3'
}
then: "commons-logging has been excluded from compile but not testCompile"
def compileFiles = project.configurations.compile.resolve()
compileFiles.size() == 4
compileFiles.collect { it.name }.containsAll(['direct-exclude-1.0.jar',
'spring-tx-4.1.2.RELEASE.jar',
'spring-beans-4.1.2.RELEASE.jar',
'spring-core-4.1.2.RELEASE.jar'])
def testCompileFiles = project.configurations.testCompile.resolve()
testCompileFiles.size() == 5
testCompileFiles.collect { it.name }.containsAll(['direct-exclude-1.0.jar',
'spring-tx-4.1.2.RELEASE.jar',
'spring-beans-4.1.2.RELEASE.jar',
'spring-core-4.1.2.RELEASE.jar',
'commons-logging-1.1.3.jar'])
}
def 'Exclusions are not inherited and do not affect transitive dependencies (see gh-21)'() {
given: 'A project with a compile dependency that pulls in a JUnit exclude'
project.apply plugin: 'io.spring.dependency-management'
project.apply plugin: 'java'
project.dependencyManagement {
imports {
mavenBom 'org.springframework.boot:spring-boot-dependencies:1.2.0.RELEASE'
}
}
project.dependencies {
compile 'org.codehaus.groovy:groovy'
}
when: 'It has a transitive testCompile dependency on JUnit'
project.dependencies {
testCompile 'org.springframework.boot:spring-boot-starter-test'
}
then: "JUnit has not be excluded"
def testCompileFiles = project.configurations.testCompile.resolve()
testCompileFiles.size() == 9
testCompileFiles
.collect { it.name }
.containsAll(['groovy-2.3.8.jar',
'spring-boot-starter-test-1.2.0.RELEASE.jar',
'junit-4.12.jar',
'mockito-core-1.10.8.jar',
'hamcrest-core-1.3.jar',
'hamcrest-library-1.3.jar',
'spring-core-4.1.3.RELEASE.jar',
'spring-test-4.1.3.RELEASE.jar',
'objenesis-2.1.jar'])
}
def "Exclusions from a dependency's ancestors are applied correctly (see gh-23)"() {
given: "A project with the plugin applied that depends on Spring Cloud's Zuul starter"
project.apply plugin: 'io.spring.dependency-management'
project.apply plugin: 'java'
project.dependencies {
compile 'org.springframework.cloud:spring-cloud-starter-zuul:1.0.0.RC1'
}
project.repositories {
maven { url 'https://repo.spring.io/libs-milestone' }
}
when: 'The configuration is resolved'
def files = project.configurations.compile.resolve()
then: 'ribbon-loadbalancer has not be excluded'
files.collect { it.name }
.contains 'ribbon-loadbalancer-2.0-RC13.jar'
}
def "Pom exclusions can be disabled"() {
given: 'A project that imports a bom and disables pom exclusions'
project.apply plugin: 'io.spring.dependency-management'
project.apply plugin: 'java'
project.dependencyManagement {
imports {
mavenBom 'io.spring.platform:platform-bom:1.0.1.RELEASE'
}
applyMavenExclusions = false
}
project.dependencies {
compile 'org.springframework:spring-core'
}
when: 'A configuration is resolved'
def files = project.configurations.compile.resolve()
then: "The bom's dependency management has been applied but the exclusions have not"
files.size() == 2
files.collect { it.name }.containsAll(['spring-core-4.0.6.RELEASE.jar',
'commons-logging-1.1.3.jar'])
}
def "Exclusions are applied correctly to dependencies that are referenced multiple times"() {
given: 'A project that depends on spring-boot-starter-remote-shall'
project.apply plugin: 'io.spring.dependency-management'
project.apply plugin: 'java'
project.dependencies {
compile 'org.springframework.boot:spring-boot-starter-remote-shell:1.2.0.RELEASE'
}
when: "its compile configuration is resolved"
def files = project.configurations.compile.resolve()
then: "groovy-all has been excluded"
files.collect { it.name }.findAll { it.startsWith 'groovy-all' } .size() == 0
}
def "Transitive dependencies with a circular reference are tolerated (see gh-33)"() {
given: 'A project that depends on org.apache.xmlgraphics:batik-rasterizer'
project.apply plugin: 'io.spring.dependency-management'
project.apply plugin: 'java'
project.dependencies {
compile 'org.apache.xmlgraphics:batik-rasterizer:1.7'
}
when: "its compile configuration is resolved"
def files = project.configurations.compile.resolve()
then: "there is no StackOverflowException and resolution succeeds"
!files.empty
}
def "The resolution strategy of a dependency management configuration can be customized"() {
when: 'A project has the plugin applied'
project.apply plugin: 'io.spring.dependency-management'
project.apply plugin: 'java'
then: "The resolution strategy can be customized"
project.dependencyManagement {
resolutionStrategy {
cacheChangingModulesFor 0, 'seconds'
}
}
}
def "A managed dependency can be configured using a GString"() {
given: 'A project that has the plugin applied'
project.apply plugin: 'io.spring.dependency-management'
project.apply plugin: 'java'
when: "A managed dependency is configured using a GString"
def springVersion = '4.1.5.RELEASE'
project.dependencyManagement {
dependencies {
dependency "org.springframework:spring-core:$springVersion"
}
}
then: 'The managed version has been configured correctly'
'4.1.5.RELEASE' == project.dependencyManagement.managedVersions['org.springframework:spring-core']
}
def "Exclusions are handled correctly for dependencies that appear multiple times"() {
given: 'A project that has the plugin applied'
project.apply plugin: 'io.spring.dependency-management'
project.apply plugin: 'java'
when: "It has dependencies that depend on and exclude javax.validation:validation-api"
project.dependencies {
compile("org.springframework.cloud:spring-cloud-starter-eureka:1.0.0.RELEASE")
compile("org.springframework.boot:spring-boot-starter-web:1.2.3.RELEASE")
}
then: 'validation-api has not been excluded'
def files = project.configurations.compile.resolve()