-
Notifications
You must be signed in to change notification settings - Fork 4.6k
/
ConfigurationOnDemandIntegrationTest.groovy
564 lines (455 loc) · 16.5 KB
/
ConfigurationOnDemandIntegrationTest.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
/*
* Copyright 2012 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.api
import org.gradle.integtests.fixtures.AbstractIntegrationSpec
import org.gradle.integtests.fixtures.ToBeFixedForConfigurationCache
import org.gradle.integtests.fixtures.executer.GradleContextualExecuter
import org.gradle.integtests.fixtures.executer.ProjectLifecycleFixture
import org.gradle.integtests.fixtures.extensions.FluidDependenciesResolveTest
import org.gradle.integtests.fixtures.timeout.IntegrationTestTimeout
import org.junit.Rule
import spock.lang.IgnoreIf
import spock.lang.Issue
@FluidDependenciesResolveTest
class ConfigurationOnDemandIntegrationTest extends AbstractIntegrationSpec {
@Rule ProjectLifecycleFixture fixture = new ProjectLifecycleFixture(executer, temporaryFolder)
def setup() {
file("gradle.properties") << "org.gradle.configureondemand=true"
}
@IgnoreIf({ GradleContextualExecuter.isParallel() }) //parallel mode hides incubating message
def "presents incubating message"() {
file("gradle.properties") << "org.gradle.configureondemand=false"
buildFile << "task foo"
when:
run("foo", "--configure-on-demand")
then:
fixture.assertProjectsConfigured(":")
output.count("Configuration on demand is an incubating feature") == 1
}
@IgnoreIf({ GradleContextualExecuter.isParallel() }) //parallel mode hides incubating message
def "presents incubating message with parallel mode"() {
file("gradle.properties") << "org.gradle.configureondemand=false"
buildFile << "task foo"
when:
run("foo", "--configure-on-demand", "--parallel")
then:
fixture.assertProjectsConfigured(":")
output.count("Configuration on demand is an incubating feature") == 1
}
def "can be enabled from command line for a single module build"() {
file("gradle.properties") << "org.gradle.configureondemand=false"
buildFile << "task foo"
when:
run("foo", "--configure-on-demand")
then:
fixture.assertProjectsConfigured(":")
}
def "evaluates only project referenced in the task list"() {
settingsFile << "include 'api', 'impl', 'util', 'util:impl'"
buildFile << "allprojects { task foo }"
when:
run(":util:impl:foo")
then:
fixture.assertProjectsConfigured(":", ":util", ":util:impl")
}
def "does not show configuration on demand incubating message in a regular mode"() {
file("gradle.properties").text = "org.gradle.configureondemand=false"
when:
run()
then:
!output.contains("Configuration on demand is incubating")
}
@ToBeFixedForConfigurationCache(because = "test expects configuration phase")
def "follows java project dependencies"() {
settingsFile << "include 'api', 'impl', 'util'"
buildFile << "allprojects { apply plugin: 'java-library' } "
file("impl/build.gradle") << "dependencies { api project(':api') } "
file("util/build.gradle") << "dependencies { implementation project(':impl') } "
//util -> impl -> api
file("api/src/main/java/Person.java") << """public interface Person {
String getName();
}
"""
file("impl/src/main/java/PersonImpl.java") << """public class PersonImpl implements Person {
public String getName() {
return "Szczepan";
}
}
"""
file("util/src/main/java/Utility.java") << "public class Utility extends PersonImpl {}"
when:
run(":api:build")
then:
fixture.assertProjectsConfigured(":", ":api")
when:
inDirectory("impl")
run(":api:build")
then:
fixture.assertProjectsConfigured(":", ":api")
when:
run(":impl:build")
then:
fixture.assertProjectsConfigured(":", ":impl", ":api")
when:
run(":util:build")
then:
fixture.assertProjectsConfigured(":", ":util", ":impl", ":api")
}
def "can have cycles in project dependencies"() {
settingsFile << "include 'api', 'impl', 'util'"
buildFile << """
allprojects { apply plugin: 'java-library' }
project(':impl') {
dependencies { implementation project(path: ':api', configuration: 'archives') }
}
project(':api') {
dependencies { runtimeOnly project(':impl') }
task run(dependsOn: configurations.runtimeClasspath)
}
"""
when:
run(":api:run")
then:
fixture.assertProjectsConfigured(":", ":api", ':impl')
}
def "follows project dependencies when run in subproject"() {
settingsFile << "include 'api', 'impl', 'util'"
file("api/build.gradle") << "configurations { api }"
file("impl/build.gradle") << """
configurations { util }
dependencies { util project(path: ':api', configuration: 'api') }
task build(dependsOn: configurations.util)
"""
when:
inDirectory("impl")
run("build")
then:
fixture.assertProjectsConfigured(':', ':impl', ':api')
}
def "name matching execution from root evaluates all projects"() {
settingsFile << "include 'api', 'impl'"
buildFile << "task foo"
when:
run("foo")
then:
fixture.assertProjectsConfigured(":", ":api", ":impl")
when:
run(":foo")
then:
fixture.assertProjectsConfigured(":")
}
def "name matching execution from subproject evaluates only the subproject recursively"() {
settingsFile << "include 'api', 'impl:one', 'impl:two', 'impl:two:abc'"
file("impl/build.gradle") << "task foo"
when:
inDirectory("impl")
run("foo")
then:
fixture.assertProjectsConfigured(":", ":impl", ":impl:one", ":impl:two", ":impl:two:abc")
}
def "may run implicit tasks from root"() {
settingsFile << "include 'api', 'impl'"
when:
run(":help")
then:
fixture.assertProjectsConfigured(":")
}
def "may run implicit tasks for subproject"() {
settingsFile << "include 'api', 'impl'"
when:
run(":api:help")
then:
fixture.assertProjectsConfigured(":", ":api")
}
def "respects default tasks"() {
settingsFile << "include 'api', 'impl'"
file("api/build.gradle") << """
task foo
defaultTasks 'foo'
"""
when:
inDirectory('api')
run()
then:
fixture.assertProjectsConfigured(":", ":api")
result.assertTasksExecuted(':api:foo')
}
def "respects evaluationDependsOn"() {
settingsFile << "include 'api', 'impl', 'other'"
file("api/build.gradle") << """
evaluationDependsOn(":impl")
"""
when:
run("api:help")
then:
fixture.assertProjectsConfigured(":", ":impl", ":api")
}
@ToBeFixedForConfigurationCache(because = "test expects configuration phase")
def "respects buildProjectDependencies setting"() {
settingsFile << "include 'api', 'impl', 'other'"
file("impl/build.gradle") << """
apply plugin: 'java-library'
dependencies { implementation project(":api") }
"""
file("api/build.gradle") << "apply plugin: 'java'"
// Provide a source file so that the compile task doesn't skip resolving inputs
file("impl/src/main/java/Foo.java") << "public class Foo {}"
when:
run("impl:build")
then:
executed ":api:jar", ":impl:jar"
fixture.assertProjectsConfigured(":", ":impl", ":api")
when:
run("impl:build", "--no-rebuild") // impl -> api
then:
executed ":impl:jar"
notExecuted ":api:jar"
// :api is configured to resolve impl.compileClasspath configuration
fixture.assertProjectsConfigured(":", ":impl", ":api")
}
def "respects external task dependencies"() {
settingsFile << "include 'api', 'impl', 'other'"
file("build.gradle") << "allprojects { task foo }"
file("impl/build.gradle") << """
task bar(dependsOn: ":api:foo")
"""
when:
run("impl:bar")
then:
fixture.assertProjectsConfigured(":", ":impl", ":api")
result.assertTasksExecutedInOrder(":api:foo", ":impl:bar")
}
def "supports buildSrc"() {
file("buildSrc/src/main/java/FooTask.java") << """
import org.gradle.api.DefaultTask;
import org.gradle.api.tasks.TaskAction;
public class FooTask extends DefaultTask {
@TaskAction public void logStuff(){
System.out.println(String.format("Horray!!! '%s' executed.", getName()));
}
}
"""
buildFile << "task foo(type: FooTask)"
when:
run("foo", "-s")
then:
output.contains "Horray!!!"
}
def "may configure project at execution time"() {
settingsFile << "include 'a', 'b', 'c'"
file('a/build.gradle') << """
configurations { conf }
dependencies { conf project(path: ":b", configuration: "conf") }
task resolveConf {
doLast {
//resolves at execution time, forcing 'b' to get configured
configurations.conf.files
}
}
"""
file('b/build.gradle') << """
configurations { conf }
"""
when:
run(":a:resolveConf", "-i")
then:
fixture.assertProjectsConfigured(":", ":a", ":b")
}
def "handles buildNeeded"() {
settingsFile << "include 'a', 'b', 'c'"
file("a/build.gradle") << """ apply plugin: 'java' """
file("b/build.gradle") << """
apply plugin: 'java'
project(':b') {
dependencies { implementation project(':a') }
}
"""
when:
run(":b:buildNeeded")
then:
executed ':b:buildNeeded', ':a:buildNeeded'
fixture.assertProjectsConfigured(":", ":b", ":a")
}
def "handles buildDependents"() {
settingsFile << "include 'a', 'b', 'c'"
file("a/build.gradle") << """ apply plugin: 'java' """
file("b/build.gradle") << """
apply plugin: 'java'
project(':b') {
dependencies { implementation project(':a') }
}
"""
when:
run(":a:buildDependents")
then:
executed ':b:buildDependents', ':a:buildDependents'
//unfortunately buildDependents requires all projects to be configured
fixture.assertProjectsConfigured(":", ":a", ":b", ":c")
}
def "task command-line argument may look like a task path"() {
settingsFile << "include 'a', 'b', 'c'"
file("a/build.gradle") << """
task one(type: SomeTask)
task two(type: SomeTask)
class SomeTask extends DefaultTask {
@org.gradle.api.tasks.options.Option(description="some value")
@Input
String value
}
"""
when:
run(":a:one", "--value", ":b:thing", "a:two", "--value", "unknown:unknown")
then:
result.assertTasksExecuted(":a:one", ":a:two")
fixture.assertProjectsConfigured(":", ":a")
}
def "does not configure all projects when excluded task path is not qualified and is exact match for task in default project"() {
settingsFile << "include 'a', 'a:child', 'b', 'b:child', 'c'"
file('a').mkdirs()
file('b').mkdirs()
buildFile << """
allprojects {
task one
task two
task three
}
"""
when:
run(":a:one", "-x", "two", "-x", "three")
then:
result.assertTasksExecuted(":a:one")
fixture.assertProjectsConfigured(":", ":a")
when:
executer.usingProjectDirectory(file('a'))
run(":a:one", "-x", "two", "-x", "three")
then:
result.assertTasksExecuted(":a:one")
fixture.assertProjectsConfigured(":", ":a")
when:
executer.usingProjectDirectory(file('b'))
run(":a:one", "-x", "two", "-x", "three")
then:
result.assertTasksExecuted(":a:one")
fixture.assertProjectsConfigured(":", ":a", ":b")
}
def "does not configure all projects when excluded task path is not qualified and an exact match for task has already been seen in some sub-project of default project"() {
settingsFile << "include 'a', 'b', 'c', 'c:child'"
file('c').mkdirs()
buildFile << """
allprojects {
task one
}
project(':b') {
task two
}
"""
when:
run(":a:one", "-x", "two")
then:
result.assertTasksExecuted(":a:one")
fixture.assertProjectsConfigured(":", ":a")
when:
executer.usingProjectDirectory(file("c"))
runAndFail(":a:one", "-x", "two")
then:
failure.assertHasDescription("Task 'two' not found in project ':c' and its subprojects.")
fixture.assertProjectsConfigured(":", ":a", ":c", ':c:child')
}
def "configures all subprojects of default project when excluded task path is not qualified and an exact match not found in default project"() {
settingsFile << "include 'a', 'b', 'c', 'c:child'"
file('c').mkdirs()
buildFile << """
allprojects {
task one
}
"""
file("b/build.gradle") << "task two"
when:
run(":a:one", "-x", "two")
then:
result.assertTasksExecuted(":a:one")
fixture.assertProjectsConfigured(":", ":a", ":b", ":c", ":c:child")
when:
executer.usingProjectDirectory(file("c"))
runAndFail(":a:one", "-x", "two")
then:
failure.assertHasDescription("Task 'two' not found in project ':c' and its subprojects.")
fixture.assertProjectsConfigured(":", ":a", ":c", ':c:child')
}
def "configures all subprojects of default projects when excluded task path is not qualified and uses camel case matching"() {
settingsFile << "include 'a', 'b', 'b:child', 'c'"
file('b').mkdirs()
buildFile << """
allprojects {
task one
task two
}
"""
when:
run(":a:one", "-x", "tw")
then:
result.assertTasksExecuted(":a:one")
fixture.assertProjectsConfigured(":", ":a", ":b", ":c", ":b:child")
when:
executer.usingProjectDirectory(file('b'))
run(":a:one", "-x", "tw")
then:
result.assertTasksExecuted(":a:one")
fixture.assertProjectsConfigured(":", ":a", ":b", ":b:child")
}
def "extra properties defined in parent project are accessible to child"() {
settingsFile << "include 'a', 'a:child'"
file('a/build.gradle') << """
ext.foo = "Moo!!!"
"""
file('a/child/build.gradle') << """
task printExt {
doLast {
println "The Foo says " + foo
}
}
"""
when:
run(":a:child:printExt")
then:
outputContains("The Foo says Moo!!!")
}
@ToBeFixedForConfigurationCache(because = "test expects configuration phase on second run")
@Issue("https://github.com/gradle/gradle/issues/18460")
@IntegrationTestTimeout(value = 60, onlyIf = { GradleContextualExecuter.embedded })
def "can query dependencies with configure on demand enabled"() {
def subprojects = ["a", "b"]
multiProjectBuild("outputRegistry", subprojects)
subprojects.each { projectName ->
file("${projectName}/build.gradle") << """
plugins {
id("java-library")
}
"""
}
file("a/build.gradle") << """
dependencies {
implementation(project(":b"))
}
"""
when:
succeeds("a:dependencies", "--configure-on-demand", "--debug")
then:
outputContains("More outputs are being registered even though the build output cleanup registry has already been finalized.")
expect:
succeeds("a:dependencies", "--configure-on-demand")
}
}