/
AbstractCrossTaskIncrementalCompilationIntegrationTest.groovy
1039 lines (869 loc) · 38.6 KB
/
AbstractCrossTaskIncrementalCompilationIntegrationTest.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 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 org.gradle.java.compile.incremental
import groovy.transform.NotYetImplemented
import org.gradle.integtests.fixtures.CompilationOutputsFixture
import org.gradle.integtests.fixtures.CompiledLanguage
import org.gradle.integtests.fixtures.ToBeFixedForConfigurationCache
import org.gradle.integtests.fixtures.executer.GradleContextualExecuter
import spock.lang.Ignore
import spock.lang.IgnoreIf
import spock.lang.Issue
import spock.lang.Unroll
abstract class AbstractCrossTaskIncrementalCompilationIntegrationTest extends AbstractJavaGroovyIncrementalCompilationSupport {
CompilationOutputsFixture impl
def setup() {
impl = new CompilationOutputsFixture(file("impl/build/classes"))
buildFile << """
subprojects {
apply plugin: '${language.name}'
apply plugin: 'java-library'
${mavenCentralRepository()}
configurations.compileClasspath.attributes.attribute(LibraryElements.LIBRARY_ELEMENTS_ATTRIBUTE, objects.named(LibraryElements, LibraryElements.${useJar ? 'JAR' : 'CLASSES'}))
}
$projectDependencyBlock
"""
settingsFile << "include 'api', 'impl'"
if (language == CompiledLanguage.GROOVY) {
configureGroovyIncrementalCompilation('subprojects')
}
}
protected String getProjectDependencyBlock() {
'''
project(':impl') {
dependencies { api project(':api') }
}
'''
}
protected void addDependency(String from, String to) {
buildFile << """
project(':$from') {
dependencies { api project(':$to') }
}
"""
}
protected abstract boolean isUseJar()
private void clearImplProjectDependencies() {
buildFile << """
project(':impl') {
configurations.api.dependencies.clear() //so that api jar is no longer on classpath
}
"""
configureGroovyIncrementalCompilation('subprojects')
}
File source(Map projectToClassBodies) {
File out
projectToClassBodies.each { project, bodies ->
bodies.each { body ->
def className = (body =~ /(?s).*?(?:class|interface) (\w+) .*/)[0][1]
assert className: "unable to find class name"
def f = file("$project/src/main/${language.name}/${className}.${language.name}")
f.createFile()
f.text = body
out = f
}
}
out
}
@ToBeFixedForConfigurationCache(
bottomSpecs = [
"CrossTaskIncrementalGroovyCompilationUsingClassDirectoryIntegrationTest",
"CrossTaskIncrementalGroovyCompilationUsingJarIntegrationTest"
],
because = "gradle/configuration-cache#270"
)
def "detects changed class in an upstream project"() {
source api: ["class A {}", "class B {}"], impl: ["class ImplA extends A {}", "class ImplB extends B {}"]
impl.snapshot { run language.compileTaskName }
when:
source api: ["class A { String change; }"]
run "impl:${language.compileTaskName}"
then:
impl.recompiledClasses("ImplA")
}
@ToBeFixedForConfigurationCache(
bottomSpecs = [
"CrossTaskIncrementalGroovyCompilationUsingClassDirectoryIntegrationTest",
"CrossTaskIncrementalGroovyCompilationUsingJarIntegrationTest"
],
because = "gradle/configuration-cache#270"
)
def "detects change to transitive superclass in an upstream project"() {
settingsFile << """
include 'app'
"""
addDependency("app", "impl")
def app = new CompilationOutputsFixture(file("app/build/classes"))
source api: ["class A {}"]
source impl: ["class B extends A {}"]
source app: ["class Unrelated {}", "class C extends B {}", "class D extends C {}"]
app.snapshot { run language.compileTaskName }
when:
source api: ["class A { String change; }"]
run "app:${language.compileTaskName}"
then:
app.recompiledClasses("C", "D")
}
@ToBeFixedForConfigurationCache(
bottomSpecs = [
"CrossTaskIncrementalGroovyCompilationUsingClassDirectoryIntegrationTest",
"CrossTaskIncrementalGroovyCompilationUsingJarIntegrationTest"
],
because = "gradle/configuration-cache#270"
)
def "detects change to transitive dependency in an upstream project"() {
settingsFile << """
include 'app'
"""
addDependency("app", "impl")
def app = new CompilationOutputsFixture(file("app/build/classes"))
source api: ["class A {}"]
source impl: ["class B { public A a;}"]
source app: ["class Unrelated {}", "class C { public B b; }"]
app.snapshot { run language.compileTaskName }
when:
source api: ["class A { String change; }"]
run "app:${language.compileTaskName}"
then:
app.recompiledClasses("C")
}
@ToBeFixedForConfigurationCache(
bottomSpecs = [
"CrossTaskIncrementalGroovyCompilationUsingClassDirectoryIntegrationTest",
"CrossTaskIncrementalGroovyCompilationUsingJarIntegrationTest"
],
because = "gradle/configuration-cache#270"
)
def "detects deletions of transitive dependency in an upstream project"() {
settingsFile << """
include 'app'
"""
addDependency("app", "impl")
def app = new CompilationOutputsFixture(file("app/build/classes"))
source api: ["class A {}"]
source impl: ["class B { public A a;}"]
source app: ["class Unrelated {}", "class C { public B b; }"]
app.snapshot {
impl.snapshot {
run language.compileTaskName
}
}
when:
file("api/src/main/${language.name}/A.${language.name}").delete()
run "app:${language.compileTaskName}", "-x", "impl:${language.compileTaskName}"
then:
impl.noneRecompiled()
app.recompiledClasses("C")
}
@ToBeFixedForConfigurationCache(
bottomSpecs = [
"CrossTaskIncrementalGroovyCompilationUsingClassDirectoryIntegrationTest",
"CrossTaskIncrementalGroovyCompilationUsingJarIntegrationTest"
],
because = "gradle/configuration-cache#270"
)
def "deletion of jar without dependents does not recompile any classes"() {
source api: ["class A {}"], impl: ["class SomeImpl {}"]
impl.snapshot { run language.compileTaskName }
when:
clearImplProjectDependencies()
run "impl:${language.compileTaskName}"
then:
impl.noneRecompiled()
}
@ToBeFixedForConfigurationCache(
bottomSpecs = [
"CrossTaskIncrementalGroovyCompilationUsingClassDirectoryIntegrationTest",
"CrossTaskIncrementalGroovyCompilationUsingJarIntegrationTest"
],
because = "gradle/configuration-cache#270"
)
def "deletion of jar with dependents causes compilation failure"() {
source api: ["class A {}"], impl: ["class ImplA extends A {}"]
impl.snapshot { run language.compileTaskName }
when:
clearImplProjectDependencies()
fails "impl:${language.compileTaskName}"
then:
impl.noneRecompiled()
}
@ToBeFixedForConfigurationCache(
bottomSpecs = [
"CrossTaskIncrementalGroovyCompilationUsingClassDirectoryIntegrationTest",
"CrossTaskIncrementalGroovyCompilationUsingJarIntegrationTest"
],
because = "gradle/configuration-cache#270"
)
def "detects change to dependency and ensures class dependency info refreshed"() {
source api: ["class A {}", "class B extends A {}"]
source impl: ["class SomeImpl {}", "class ImplB extends B {}", "class ImplB2 extends ImplB {}"]
impl.snapshot { run language.compileTaskName }
when:
source api: ["class B { /* remove extends */ }"]
run "impl:${language.compileTaskName}"
then:
impl.recompiledClasses("ImplB", "ImplB2")
when:
impl.snapshot()
source api: ["class A { /* change */ }"]
run "impl:${language.compileTaskName}"
then:
impl.noneRecompiled() //because after earlier change to B, class A is no longer a dependency
}
@ToBeFixedForConfigurationCache(
bottomSpecs = [
"CrossTaskIncrementalGroovyCompilationUsingClassDirectoryIntegrationTest",
"CrossTaskIncrementalGroovyCompilationUsingJarIntegrationTest"
],
because = "gradle/configuration-cache#270"
)
def "detects deleted class in an upstream project and fails compilation"() {
def b = source(api: ["class A {}", "class B {}"])
source impl: ["class ImplA extends A {}", "class ImplB extends B {}"]
impl.snapshot { run language.compileTaskName }
when:
assert b.delete()
fails "impl:${language.compileTaskName}"
then:
impl.noneRecompiled()
}
@ToBeFixedForConfigurationCache(
bottomSpecs = [
"CrossTaskIncrementalGroovyCompilationUsingClassDirectoryIntegrationTest",
"CrossTaskIncrementalGroovyCompilationUsingJarIntegrationTest"
],
because = "gradle/configuration-cache#270"
)
def "recompilation not necessary when upstream does not change any of the actual dependencies"() {
source api: ["class A {}", "class B {}"], impl: ["class ImplA extends A {}"]
impl.snapshot { run language.compileTaskName }
when:
source api: ["class B { String change; }"]
run "impl:${language.compileTaskName}"
then:
impl.noneRecompiled()
}
@NotYetImplemented
// Can re-enable with compiler plugins. See gradle/gradle#1474
def "deletion of jar with non-private constant causes rebuild if constant is used"() {
source api: ["class A { public final static int x = 1; }"], impl: ["class X { int x() { return 1;} }", "class Y {}"]
impl.snapshot { run language.compileTaskName }
when:
run "impl:${language.compileTaskName}"
then:
impl.recompiledClasses("X")
}
@Unroll
@NotYetImplemented
// Can re-enable with compiler plugins. See gradle/gradle#1474
def "change in an upstream class with non-private constant causes rebuild only if same constant is used and no direct dependency (#constantType)"() {
source api: ["class A {}", "class B { final static $constantType x = $constantValue; }"], impl: ["class X { $constantType foo() { return $constantValue; }}", "class Y {int foo() { return -2; }}"]
impl.snapshot { run language.compileTaskName }
when:
source api: ["class B { /* change */ }"]
run "impl:${language.compileTaskName}"
then:
impl.recompiledClasses('X')
where:
constantType | constantValue
'boolean' | 'false'
'byte' | '(byte) 125'
'short' | '(short) 666'
'int' | '55542'
'long' | '5L'
'float' | '6f'
'double' | '7d'
'String' | '"foo"'
'String' | '"foo" + "bar"'
}
@Unroll
@NotYetImplemented
// Can re-enable with compiler plugins. See gradle/gradle#1474
def "constant value change in an upstream class causes rebuild if previous constant value was used in previous build (#constantType)"() {
source api: ["class A {}", "class B { final static $constantType x = $constantValue; }"], impl: ["class X { $constantType foo() { return $constantValue; }}", "class Y {int foo() { return -2; }}"]
impl.snapshot { run language.compileTaskName }
when:
source api: ["class B { final static $constantType x = $newValue; /* change value */ ; void blah() { /* avoid flakiness by changing compiled file length*/ } }"]
run "impl:${language.compileTaskName}"
then:
impl.recompiledClasses('X')
where:
constantType | constantValue | newValue
'boolean' | 'false' | 'true'
'byte' | '(byte) 125' | '(byte) 126'
'short' | '(short) 666' | '(short) 555'
'int' | '55542' | '444'
'long' | '5L' | '689L'
'float' | '6f' | '6.5f'
'double' | '7d' | '7.2d'
'String' | '"foo"' | '"bar"'
'String' | '"foo" + "bar"' | '"bar"'
}
@NotYetImplemented
// Can re-enable with compiler plugins. See gradle/gradle#1474
def "ignores irrelevant changes to constant values"() {
source api: ["class A {}", "class B { final static int x = 3; final static int y = -2; }"],
impl: ["class X { int foo() { return 3; }}", "class Y {int foo() { return -2; }}"]
impl.snapshot { run language.compileTaskName }
when:
source api: ["class B { final static int x = 3 ; final static int y = -3; void blah() { /* change irrelevant to constant value x */ } }"]
run "impl:${language.compileTaskName}"
then:
impl.recompiledClasses('Y')
}
@ToBeFixedForConfigurationCache(
bottomSpecs = [
"CrossTaskIncrementalGroovyCompilationUsingClassDirectoryIntegrationTest",
"CrossTaskIncrementalGroovyCompilationUsingJarIntegrationTest"
],
because = "gradle/configuration-cache#270"
)
def "change in an upstream transitive class with non-private constant does not cause full rebuild"() {
source api: ["class A { final static int x = 1; }", "class B extends A {}"], impl: ["class ImplA extends A {}", "class ImplB extends B {}"]
impl.snapshot { run language.compileTaskName }
when:
source api: ["class B { /* change */ }"]
run "impl:${language.compileTaskName}"
then:
impl.recompiledClasses('ImplB')
}
@ToBeFixedForConfigurationCache(
bottomSpecs = [
"CrossTaskIncrementalGroovyCompilationUsingClassDirectoryIntegrationTest",
"CrossTaskIncrementalGroovyCompilationUsingJarIntegrationTest"
],
because = "gradle/configuration-cache#270"
)
def "private constant in upstream project does not trigger full rebuild"() {
source api: ["class A {}", "class B { private final static int x = 1; }"], impl: ["class ImplA extends A {}", "class ImplB extends B {}"]
impl.snapshot { run language.compileTaskName }
when:
source api: ["class B { /* change */ }"]
run "impl:${language.compileTaskName}"
then:
impl.noneRecompiled()
}
@ToBeFixedForConfigurationCache(
bottomSpecs = [
"CrossTaskIncrementalGroovyCompilationUsingClassDirectoryIntegrationTest",
"CrossTaskIncrementalGroovyCompilationUsingJarIntegrationTest"
],
because = "gradle/configuration-cache#270"
)
def "addition of unused class in upstream project does not rebuild"() {
source api: ["class A {}", "class B { private final static int x = 1; }"], impl: ["class ImplA extends A {}", "class ImplB extends B {}"]
impl.snapshot { run language.compileTaskName }
when:
source api: ["class C { }"]
run "impl:${language.compileTaskName}"
then:
impl.noneRecompiled()
}
@ToBeFixedForConfigurationCache(
bottomSpecs = [
"CrossTaskIncrementalGroovyCompilationUsingClassDirectoryIntegrationTest",
"CrossTaskIncrementalGroovyCompilationUsingJarIntegrationTest"
],
because = "gradle/configuration-cache#270"
)
def "removal of unused class in upstream project does not rebuild"() {
source api: ["class A {}", "class B { private final static int x = 1; }"], impl: ["class ImplA extends A {}", "class ImplB extends B {}"]
def c = source api: ["class C { }"]
impl.snapshot { run language.compileTaskName }
when:
c.delete()
run "impl:${language.compileTaskName}"
then:
impl.noneRecompiled()
}
@NotYetImplemented
def "doesn't recompile if external dependency has ABI incompatible change but not on class we use"() {
given:
buildFile << """
project(':impl') {
${mavenCentralRepository()}
dependencies { implementation 'org.apache.commons:commons-lang3:3.3' }
}
"""
source api: ["class A {}", "class B { }"], impl: ["class ImplA extends A {}", """import org.apache.commons.lang3.StringUtils;
class ImplB extends B {
public static String HELLO = StringUtils.capitalize("hello");
}"""]
impl.snapshot { run language.compileTaskName }
when:
buildFile.text = buildFile.text.replace('3.3', '3.3.1')
run "impl:${language.compileTaskName}"
then:
impl.noneRecompiled()
}
@ToBeFixedForConfigurationCache(
bottomSpecs = [
"CrossTaskIncrementalGroovyCompilationUsingClassDirectoryIntegrationTest",
"CrossTaskIncrementalGroovyCompilationUsingJarIntegrationTest"
],
because = "gradle/configuration-cache#270"
)
def "detects changed classes when upstream project was built in isolation"() {
source api: ["class A {}", "class B {}"], impl: ["class ImplA extends A {}", "class ImplB extends B {}"]
impl.snapshot { run language.compileTaskName }
when:
source api: ["class A { String change; }"]
run "api:${language.compileTaskName}"
run "impl:${language.compileTaskName}"
then:
impl.recompiledClasses("ImplA")
}
@ToBeFixedForConfigurationCache(
bottomSpecs = [
"CrossTaskIncrementalGroovyCompilationUsingClassDirectoryIntegrationTest",
"CrossTaskIncrementalGroovyCompilationUsingJarIntegrationTest"
],
because = "gradle/configuration-cache#270"
)
def "detects class changes in subsequent runs ensuring the jar snapshots are refreshed"() {
source api: ["class A {}", "class B {}"], impl: ["class ImplA extends A {}", "class ImplB extends B {}"]
impl.snapshot { run language.compileTaskName }
when:
source api: ["class A { String change; }"]
run "api:${language.compileTaskName}"
run "impl:${language.compileTaskName}" //different build invocation
then:
impl.recompiledClasses("ImplA")
when:
impl.snapshot()
source api: ["class B { String change; }"]
run language.compileTaskName
then:
impl.recompiledClasses("ImplB")
}
def "changes to resources in jar do not incur recompilation"() {
source impl: ["class A {}"]
impl.snapshot { run "impl:${language.compileTaskName}" }
when:
file("api/src/main/resources/some-resource.txt") << "xxx"
source api: ["class A { String change; }"]
run "impl:${language.compileTaskName}"
then:
impl.noneRecompiled()
}
@ToBeFixedForConfigurationCache(
bottomSpecs = [
"CrossTaskIncrementalGroovyCompilationUsingClassDirectoryIntegrationTest",
"CrossTaskIncrementalGroovyCompilationUsingJarIntegrationTest"
],
because = "gradle/configuration-cache#270"
)
def "handles multiple compile tasks in the same project"() {
settingsFile << "\n include 'other'" //add an extra project
source impl: ["class ImplA extends A {}"], api: ["class A {}"], other: ["class Other {}"]
//new separate compile task (compileIntegTest${language.captalizedName}) depends on class from the extra project
file("impl/build.gradle") << """
sourceSets { integTest.${language.name}.srcDir "src/integTest/${language.name}" }
dependencies { integTestImplementation project(":other") }
dependencies { integTestImplementation localGroovy() }
"""
file("impl/src/integTest/${language.name}/SomeIntegTest.${language.name}") << "class SomeIntegTest extends Other {}"
impl.snapshot { run "compileIntegTest${language.capitalizedName}", language.compileTaskName }
when: //when api class is changed
source api: ["class A { String change; }"]
run "compileIntegTest${language.capitalizedName}", language.compileTaskName
then: //only impl class is recompiled
impl.recompiledClasses("ImplA")
when: //when other class is changed
impl.snapshot()
source other: ["class Other { String change; }"]
run "compileIntegTest${language.capitalizedName}", language.compileTaskName
then: //only integTest class is recompiled
impl.recompiledClasses("SomeIntegTest")
}
String wrapClassDirs(String classpath) {
if (language == CompiledLanguage.GROOVY) {
if (useJar) {
return "api.jar, ${classpath}, main"
} else {
// api/build/classes/java/main and api/build/classes/groovy/main
// impl/build/classes/java/main
return "main, main, ${classpath}, main"
}
} else {
if (useJar) {
return "api.jar, $classpath"
} else {
// api/build/classes/java/main
return "main, ${classpath}"
}
}
}
def "the order of classpath items is unchanged"() {
source api: ["class A {}"], impl: ["class B {}"]
file("impl/build.gradle") << """
dependencies { implementation "org.mockito:mockito-core:1.9.5", "junit:junit:4.13" }
tasks.named('${language.compileTaskName}') {
def classpathTxt = file("classpath.txt")
doFirst {
classpathTxt.createNewFile();
classpathTxt.text = classpath.files*.name.findAll { !it.startsWith('groovy') }.join(', ')
}
}
"""
when:
run("impl:${language.compileTaskName}") //initial run
then:
file("impl/classpath.txt").text == wrapClassDirs("mockito-core-1.9.5.jar, junit-4.13.jar, hamcrest-core-1.3.jar, objenesis-1.0.jar")
when: //project dependency changes
source api: ["class A { String change; }"]
run("impl:${language.compileTaskName}")
then:
file("impl/classpath.txt").text == wrapClassDirs("mockito-core-1.9.5.jar, junit-4.13.jar, hamcrest-core-1.3.jar, objenesis-1.0.jar")
when: //transitive dependency is excluded
file("impl/build.gradle") << "configurations.implementation.exclude module: 'hamcrest-core' \n"
run("impl:${language.compileTaskName}")
then:
file("impl/classpath.txt").text == wrapClassDirs("mockito-core-1.9.5.jar, junit-4.13.jar, objenesis-1.0.jar")
when: //direct dependency is excluded
file("impl/build.gradle") << "configurations.implementation.exclude module: 'junit' \n"
run("impl:${language.compileTaskName}")
then:
file("impl/classpath.txt").text == wrapClassDirs("mockito-core-1.9.5.jar, objenesis-1.0.jar")
when: //new dependency is added
file("impl/build.gradle") << "dependencies { implementation 'org.testng:testng:6.8.7' } \n"
run("impl:${language.compileTaskName}")
then:
file("impl/classpath.txt").text == wrapClassDirs("mockito-core-1.9.5.jar, testng-6.8.7.jar, objenesis-1.0.jar, bsh-2.0b4.jar, jcommander-1.27.jar, snakeyaml-1.12.jar")
}
def "handles duplicate class found in jar"() {
source api: ["class A extends B {}", "class B {}"], impl: ["class A extends C {}", "class C {}"]
impl.snapshot { run("impl:${language.compileTaskName}") }
when:
//change to source dependency duplicate triggers recompilation
source impl: ["class C { String change; }"]
run("impl:${language.compileTaskName}")
then:
impl.recompiledClasses("A", "C")
when:
//change to jar dependency duplicate is ignored because source duplicate wins
impl.snapshot()
source api: ["class B { String change; } "]
run("impl:${language.compileTaskName}")
then:
impl.noneRecompiled()
}
def "new jar with duplicate class appearing earlier on classpath must trigger compilation"() {
source impl: ["class A extends org.junit.Assert {}"]
file("impl/build.gradle") << """
configurations.implementation.dependencies.clear()
dependencies {
implementation 'junit:junit:4.13'
implementation localGroovy()
}
"""
impl.snapshot { run("impl:${language.compileTaskName}") }
when:
//add new jar with duplicate class that will be earlier on the classpath (project dependencies are earlier on classpath)
file("api/src/main/${language.name}/org/junit/Assert.${language.name}") << "package org.junit; public class Assert {}"
file("impl/build.gradle") << "dependencies { implementation project(':api') }"
run("impl:${language.compileTaskName}")
then:
impl.recompiledClasses("A")
}
def "new jar without duplicate class does not trigger compilation"() {
source impl: ["class A {}"]
impl.snapshot { run("impl:${language.compileTaskName}") }
when:
file("impl/build.gradle") << "dependencies { implementation 'junit:junit:4.13' }"
run("impl:${language.compileTaskName}")
then:
impl.noneRecompiled()
}
def "changed jar with duplicate class appearing earlier on classpath must trigger compilation"() {
source impl: ["class A extends org.junit.Assert {}"]
file("impl/build.gradle") << """
dependencies { implementation 'junit:junit:4.13' }
"""
impl.snapshot { run("impl:${language.compileTaskName}") }
when:
//update existing jar with duplicate class that will be earlier on the classpath (project dependencies are earlier on classpath)
file("api/src/main/${language.name}/org/junit/Assert.${language.name}") << "package org.junit; public class Assert {}"
run("impl:${language.compileTaskName}")
then:
impl.recompiledClasses("A")
}
def "deletion of a jar with duplicate class causes recompilation"() {
file("api/src/main/${language.name}/org/junit/Assert.${language.name}") << "package org.junit; public class Assert {}"
source impl: ["class A extends org.junit.Assert {}"]
file("impl/build.gradle") << "dependencies { implementation 'junit:junit:4.13' }"
impl.snapshot { run("impl:${language.compileTaskName}") }
when:
file("impl/build.gradle").text = """
configurations.implementation.dependencies.clear() //kill project dependency
dependencies {
implementation 'junit:junit:4.11'
implementation localGroovy()
} //leave only junit
"""
run("impl:${language.compileTaskName}")
then:
impl.recompiledClasses("A")
}
@Unroll
def "recompiles outermost class when #visibility inner class contains constant reference"() {
source api: [
"class A { public static final int EVIL = 666; }",
], impl: [
"class B {}",
"class C { $visibility static class Inner { int foo() { return A.EVIL; } } }",
"class D { $visibility class Inner { int foo() { return A.EVIL; } } }",
"class E { void foo() { Runnable r = new Runnable() { public void run() { int x = A.EVIL; } }; } }",
"""class F {
int foo() { return A.EVIL; }
$visibility static class Inner { }
}""",
]
impl.snapshot { run("impl:${language.compileTaskName}") }
when:
source api: ["class A { public static final int EVIL = 0; void blah() { /* avoid flakiness by changing compiled file length*/ } }"]
run("impl:${language.compileTaskName}")
then:
impl.recompiledClasses('B', 'C', 'C$Inner', 'D', 'D$Inner', 'E', 'E$1', 'F', 'F$Inner')
where:
visibility << ['public', 'private', '']
}
def "recognizes change of constant value in annotation"() {
source api: [
"class A { public static final int CST = 0; }",
"""import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@Retention(RetentionPolicy.RUNTIME)
@interface B { int value(); }"""
], impl: [
// cases where it's relevant, ABI-wise
"@B(A.CST) class OnClass {}",
"class OnMethod { @B(A.CST) void foo() {} }",
"class OnField { @B(A.CST) String foo; }",
"class OnParameter { void foo(@B(A.CST) int x) {} }"
]
impl.snapshot { run("impl:${language.compileTaskName}") }
when:
source api: ["class A { public static final int CST = 1234; void blah() { /* avoid flakiness by changing compiled file length*/ } }"]
run("impl:${language.compileTaskName}")
then:
impl.recompiledClasses("OnClass", "OnMethod", "OnParameter", "OnField")
}
@Unroll
@ToBeFixedForConfigurationCache(
bottomSpecs = [
"CrossTaskIncrementalGroovyCompilationUsingClassDirectoryIntegrationTest",
"CrossTaskIncrementalGroovyCompilationUsingJarIntegrationTest"
],
because = "gradle/configuration-cache#270"
)
def "change to class referenced by an annotation recompiles annotated types"() {
source api: [
"""
import java.lang.annotation.*;
@Retention(RetentionPolicy.CLASS)
public @interface B {
Class<?> value();
}
""",
"class A {}"
], impl: [
"@B(A.class) class OnClass {}",
"class OnMethod { @B(A.class) void foo() {} }",
"class OnField { @B(A.class) String foo; }",
"class OnParameter { void foo(@B(A.class) int x) {} }"
]
impl.snapshot { run language.compileTaskName }
when:
source api: [
"""
class A { public void foo() {} }
"""
]
run language.compileTaskName
then:
impl.recompiledClasses("OnClass", "OnMethod", "OnParameter", "OnField")
}
@Unroll
@ToBeFixedForConfigurationCache(
bottomSpecs = [
"CrossTaskIncrementalGroovyCompilationUsingClassDirectoryIntegrationTest",
"CrossTaskIncrementalGroovyCompilationUsingJarIntegrationTest"
],
because = "gradle/configuration-cache#270"
)
def "change to class referenced by an array value in an annotation recompiles annotated types"() {
source api: [
"""
import java.lang.annotation.*;
@Retention(RetentionPolicy.CLASS)
public @interface B {
Class<?>[] value();
}
""",
"class A {}"
], impl: [
"@B(A.class) class OnClass {}",
"class OnMethod { @B(A.class) void foo() {} }",
"class OnField { @B(A.class) String foo; }",
"class OnParameter { void foo(@B(A.class) int x) {} }"
]
impl.snapshot { run language.compileTaskName }
when:
source api: [
"""
class A { public void foo() {} }
"""
]
run language.compileTaskName
then:
impl.recompiledClasses("OnClass", "OnMethod", "OnParameter", "OnField")
}
@NotYetImplemented
@Issue("gradle/performance#335")
def "doesn't destroy class analysis when a compile error occurs"() {
source api: ["class A {}"], impl: ["class ImplA extends A {}"]
impl.snapshot { run language.compileTaskName }
when:
source api: ["class A { compile error }"]
then:
impl.snapshot { fails "impl:${language.compileTaskName}" }
when:
source api: ["class A { String foo; }"]
executer.withArgument("-i")
run "impl:${language.compileTaskName}"
then:
!output.contains('Full recompilation is required because no incremental change information is available. This is usually caused by clean builds or changing compiler arguments.')
impl.recompiledClasses("ImplA")
}
@NotYetImplemented
// Can re-enable with compiler plugins. See gradle/gradle#1474
def "only recompiles classes potentially affected by constant change"() {
source api: ["class A { public static final int FOO = 10; public static final int BAR = 20; }"],
impl: ['class B { void foo() { int x = 10; } }', 'class C { void foo() { int x = 20; } }']
impl.snapshot { run language.compileTaskName }
when:
source api: ['class A { public static final int FOO = 100; public static final int BAR = 20; }']
run "impl:${language.compileTaskName}"
then:
impl.recompiledClasses 'B'
}
@ToBeFixedForConfigurationCache(
bottomSpecs = [
"CrossTaskIncrementalGroovyCompilationUsingClassDirectoryIntegrationTest",
"CrossTaskIncrementalGroovyCompilationUsingJarIntegrationTest"
],
because = "gradle/configuration-cache#270"
)
@Ignore("This is failing on release6x and we don't want to spent time on it")
def "recompiles dependent class in case a constant is switched"() {
source api: ["class A { public static final int FOO = 10; public static final int BAR = 20; }"],
impl: ['class B { void foo() { int x = 10; } }', 'class C { void foo() { int x = 20; } }']
impl.snapshot { run language.compileTaskName }
when:
source api: ['class A { public static final int FOO = 20; public static final int BAR = 10; }']
run "impl:${language.compileTaskName}"
then:
impl.recompiledClasses 'B', 'C'
}
@Issue("gradle/gradle#1474")
@ToBeFixedForConfigurationCache(
bottomSpecs = [
"CrossTaskIncrementalGroovyCompilationUsingClassDirectoryIntegrationTest",
"CrossTaskIncrementalGroovyCompilationUsingJarIntegrationTest"
],
because = "gradle/configuration-cache#270"
)
// This is failing on release6x and we don't want to spent time on it
@IgnoreIf({ GradleContextualExecuter.isForceRealize() })
def "recompiles dependent class in case a constant is computed from another constant"() {
source api: ["class A { public static final int FOO = 10; }"], impl: ['class B { public static final int BAR = 2 + A.FOO; } ']
impl.snapshot { run language.compileTaskName }
when:
source api: ['class A { public static final int FOO = 100; }']
run "impl:${language.compileTaskName}"
then:
impl.recompiledClasses 'B'
}
@ToBeFixedForConfigurationCache(
bottomSpecs = [
"CrossTaskIncrementalGroovyCompilationUsingClassDirectoryIntegrationTest",
"CrossTaskIncrementalGroovyCompilationUsingJarIntegrationTest"
],
because = "gradle/configuration-cache#270"
)
def "detects that changed class still has the same constants so no recompile is necessary"() {
source api: ["class A { public static final int FOO = 123;}"],
impl: ["class B { void foo() { int x = 123; }}"]
impl.snapshot { run language.compileTaskName }
when:
source api: ["class A { public static final int FOO = 123; void addSomeRandomMethod() {} }"]
run "impl:${language.compileTaskName}"
then:
impl.noneRecompiled()
}
@ToBeFixedForConfigurationCache(
bottomSpecs = [
"CrossTaskIncrementalGroovyCompilationUsingClassDirectoryIntegrationTest",
"CrossTaskIncrementalGroovyCompilationUsingJarIntegrationTest"
],
because = "gradle/configuration-cache#270"
)
def "does not recompile on non-abi change across projects"() {
source api: ["class A { }"],
impl: ["class B { A a; }", "class C { B b; }"]
impl.snapshot { run language.compileTaskName }
when:
source api: ["class A { \n}"]
run "impl:${language.compileTaskName}"
then:
impl.noneRecompiled()
}
// This test checks the current behavior, not necessarily the desired one.
// If all classes are compiled by the same compile task, we do not know if a