mirror of
https://gitee.com/dcren/initializr.git
synced 2025-04-05 17:38:06 +08:00
Ensure Gradle tasks are configured lazily
At present, generated Gradle build scripts that use Groovy DSL configure tasks eagerly. This is both suboptimal and actually not aligned with the generated build scripts that use Kotlin DSL, which configures tasks lazily. This commit updates `GroovyDslGradleBuildWriter` to ensure tasks are configured lazily. See gh-1292
This commit is contained in:
parent
35e41a8f08
commit
27fc9d4067
@ -129,7 +129,7 @@ class GradleProjectGenerationConfigurationTests {
|
||||
" testImplementation 'org.springframework.boot:spring-boot-starter-test'",
|
||||
"}",
|
||||
"",
|
||||
"test {",
|
||||
"tasks.named('test') {",
|
||||
" useJUnitPlatform()",
|
||||
"}"); // @formatter:on
|
||||
}
|
||||
@ -150,7 +150,8 @@ class GradleProjectGenerationConfigurationTests {
|
||||
description.setPlatformVersion(Version.parse("2.2.4.RELEASE"));
|
||||
description.setLanguage(new JavaLanguage());
|
||||
ProjectStructure project = this.projectTester.generate(description);
|
||||
assertThat(project).textFile("build.gradle").lines().containsSequence("test {", " useJUnitPlatform()", "}");
|
||||
assertThat(project).textFile("build.gradle").lines().containsSequence("tasks.named('test') {",
|
||||
" useJUnitPlatform()", "}");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -25,6 +25,6 @@ dependencies {
|
||||
testImplementation 'org.springframework.boot:spring-boot-starter-test'
|
||||
}
|
||||
|
||||
test {
|
||||
tasks.named('test') {
|
||||
useJUnitPlatform()
|
||||
}
|
||||
|
@ -25,6 +25,6 @@ dependencyManagement {
|
||||
}
|
||||
}
|
||||
|
||||
test {
|
||||
tasks.named('test') {
|
||||
useJUnitPlatform()
|
||||
}
|
||||
|
@ -27,6 +27,6 @@ dependencyManagement {
|
||||
}
|
||||
}
|
||||
|
||||
test {
|
||||
tasks.named('test') {
|
||||
useJUnitPlatform()
|
||||
}
|
||||
|
@ -19,6 +19,6 @@ dependencies {
|
||||
testImplementation 'org.springframework.boot:spring-boot-starter-test'
|
||||
}
|
||||
|
||||
test {
|
||||
tasks.named('test') {
|
||||
useJUnitPlatform()
|
||||
}
|
||||
|
@ -29,6 +29,6 @@ tasks.withType(KotlinCompile) {
|
||||
}
|
||||
}
|
||||
|
||||
test {
|
||||
tasks.named('test') {
|
||||
useJUnitPlatform()
|
||||
}
|
||||
|
@ -20,6 +20,6 @@ dependencies {
|
||||
testImplementation 'org.springframework.boot:spring-boot-starter-test'
|
||||
}
|
||||
|
||||
test {
|
||||
tasks.named('test') {
|
||||
useJUnitPlatform()
|
||||
}
|
||||
|
@ -18,6 +18,6 @@ dependencies {
|
||||
testImplementation 'org.springframework.boot:spring-boot-starter-test'
|
||||
}
|
||||
|
||||
test {
|
||||
tasks.named('test') {
|
||||
useJUnitPlatform()
|
||||
}
|
||||
|
@ -22,6 +22,6 @@ dependencies {
|
||||
testImplementation 'org.springframework.boot:spring-boot-starter-test'
|
||||
}
|
||||
|
||||
test {
|
||||
tasks.named('test') {
|
||||
useJUnitPlatform()
|
||||
}
|
||||
|
@ -18,6 +18,6 @@ dependencies {
|
||||
testImplementation 'org.springframework.boot:spring-boot-starter-test'
|
||||
}
|
||||
|
||||
test {
|
||||
tasks.named('test') {
|
||||
useJUnitPlatform()
|
||||
}
|
||||
|
@ -20,6 +20,6 @@ dependencies {
|
||||
testImplementation 'org.springframework.boot:spring-boot-starter-test'
|
||||
}
|
||||
|
||||
test {
|
||||
tasks.named('test') {
|
||||
useJUnitPlatform()
|
||||
}
|
||||
|
@ -17,6 +17,6 @@ dependencies {
|
||||
testImplementation 'org.springframework.boot:spring-boot-starter-test'
|
||||
}
|
||||
|
||||
test {
|
||||
tasks.named('test') {
|
||||
useJUnitPlatform()
|
||||
}
|
||||
|
@ -19,6 +19,6 @@ dependencies {
|
||||
testImplementation 'org.springframework.boot:spring-boot-starter-test'
|
||||
}
|
||||
|
||||
test {
|
||||
tasks.named('test') {
|
||||
useJUnitPlatform()
|
||||
}
|
||||
|
@ -29,6 +29,6 @@ tasks.withType(KotlinCompile) {
|
||||
}
|
||||
}
|
||||
|
||||
test {
|
||||
tasks.named('test') {
|
||||
useJUnitPlatform()
|
||||
}
|
||||
|
@ -31,6 +31,6 @@ tasks.withType(KotlinCompile) {
|
||||
}
|
||||
}
|
||||
|
||||
test {
|
||||
tasks.named('test') {
|
||||
useJUnitPlatform()
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2020 the original author or authors.
|
||||
* Copyright 2012-2021 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.
|
||||
@ -190,7 +190,7 @@ public class GroovyDslGradleBuildWriter extends GradleBuildWriter {
|
||||
});
|
||||
tasks.values().filter((candidate) -> candidate.getType() == null).forEach((task) -> {
|
||||
writer.println();
|
||||
writer.println(task.getName() + " {");
|
||||
writer.println("tasks.named('" + task.getName() + "') {");
|
||||
writer.indented(() -> writeTaskCustomization(writer, task));
|
||||
writer.println("}");
|
||||
});
|
||||
|
@ -170,7 +170,8 @@ class GroovyDslGradleBuildWriterTests {
|
||||
task.invoke("dependsOn", "test");
|
||||
});
|
||||
List<String> lines = generateBuild(build);
|
||||
assertThat(lines).containsSequence("asciidoctor {", " inputs.dir snippetsDir", " dependsOn test", "}");
|
||||
assertThat(lines).containsSequence("tasks.named('asciidoctor') {", " inputs.dir snippetsDir",
|
||||
" dependsOn test", "}");
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -178,7 +179,7 @@ class GroovyDslGradleBuildWriterTests {
|
||||
GradleBuild build = new GradleBuild();
|
||||
build.tasks().customize("test", (task) -> task.invoke("myMethod"));
|
||||
List<String> lines = generateBuild(build);
|
||||
assertThat(lines).containsSequence("test {", " myMethod()", "}");
|
||||
assertThat(lines).containsSequence("tasks.named('test') {", " myMethod()", "}");
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -189,7 +190,7 @@ class GroovyDslGradleBuildWriterTests {
|
||||
task.attribute("kotlinOptions.jvmTarget", "'1.8'");
|
||||
});
|
||||
List<String> lines = generateBuild(build);
|
||||
assertThat(lines).containsSequence("compileKotlin {",
|
||||
assertThat(lines).containsSequence("tasks.named('compileKotlin') {",
|
||||
" kotlinOptions.freeCompilerArgs = ['-Xjsr305=strict']", " kotlinOptions.jvmTarget = '1.8'", "}");
|
||||
}
|
||||
|
||||
@ -202,7 +203,7 @@ class GroovyDslGradleBuildWriterTests {
|
||||
kotlinOptions.attribute("jvmTarget", "'1.8'");
|
||||
}));
|
||||
List<String> lines = generateBuild(build);
|
||||
assertThat(lines).containsSequence("compileKotlin {", " kotlinOptions {",
|
||||
assertThat(lines).containsSequence("tasks.named('compileKotlin') {", " kotlinOptions {",
|
||||
" freeCompilerArgs = ['-Xjsr305=strict']", " jvmTarget = '1.8'", " }", "}");
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user