diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/asciidoc/getting-started.adoc b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/asciidoc/getting-started.adoc index 15ea2e2afa74..3ef9c146fd65 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/asciidoc/getting-started.adoc +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/asciidoc/getting-started.adoc @@ -19,77 +19,83 @@ include::../gradle/getting-started/apply-plugin-release.gradle.kts[] ---- endif::[] ifeval::["{version-type}" == "MILESTONE"] -The plugin is published to the Spring milestones repository. - -For Gradle versions less than 4.10, you must apply the plugin imperatively: +The plugin is published to the Spring milestones repository. For Gradle versions less +than 4.10, this means that you must apply the plugin imperatively: [source,groovy,indent=0,subs="verbatim,attributes"] ---- include::../gradle/getting-started/apply-plugin-milestone.gradle[] ---- -For Gradle 4.10 and above, it can be applied using the `plugins` block: +For Gradle 4.10 and above, Gradle can be configured to use the milestones repository +and it can be applied using the `plugins` block. To configure Gradle to use the milestones +repository, add the following to your `settings.gradle` (Groovy) or `settings.gradle.kts` +(Kotlin): + [source,groovy,indent=0,subs="verbatim,attributes",role="primary"] .Groovy ---- -include::../gradle/getting-started/apply-plugin-release.gradle[] +include::../gradle/getting-started/milestone-settings.gradle[] ---- [source,kotlin,indent=0,subs="verbatim,attributes",role="secondary"] .Kotlin ---- -include::../gradle/getting-started/apply-plugin-release.gradle.kts[] +include::../gradle/getting-started/milestone-settings.gradle.kts[] ---- -provided you add the following lines in the `settings.gradle` file (or `settings.gradle.kts` in Kotlin): +The plugin can then be applied using the `plugins` block: [source,groovy,indent=0,subs="verbatim,attributes",role="primary"] .Groovy ---- -include::../gradle/getting-started/milestone-settings.gradle[] +include::../gradle/getting-started/apply-plugin-release.gradle[] ---- [source,kotlin,indent=0,subs="verbatim,attributes",role="secondary"] .Kotlin ---- -include::../gradle/getting-started/milestone-settings.gradle.kts[] +include::../gradle/getting-started/apply-plugin-release.gradle.kts[] ---- endif::[] ifeval::["{version-type}" == "SNAPSHOT"] -The plugin is published to the Spring snapshots repository. - -For Gradle versions less than 4.10, you must apply the plugin imperatively: +The plugin is published to the Spring snapshots repository. For Gradle versions less +than 4.10, this means that you must apply the plugin imperatively: [source,groovy,indent=0,subs="verbatim,attributes"] ---- -include::../gradle/getting-started/apply-plugin-snapshot.gradle[] +include::../gradle/getting-started/apply-plugin-milestone.gradle[] ---- -For Gradle 4.10 and above, it can be applied using the `plugins` block: +For Gradle 4.10 and above, Gradle can be configured to use the snapshots repository +and it can be applied using the `plugins` block. To configure Gradle to use the snapshots +repository, add the following to your `settings.gradle` (Groovy) or `settings.gradle.kts` +(Kotlin): + [source,groovy,indent=0,subs="verbatim,attributes",role="primary"] .Groovy ---- -include::../gradle/getting-started/apply-plugin-release.gradle[] +include::../gradle/getting-started/snapshot-settings.gradle[] ---- [source,kotlin,indent=0,subs="verbatim,attributes",role="secondary"] .Kotlin ---- -include::../gradle/getting-started/apply-plugin-release.gradle.kts[] +include::../gradle/getting-started/snapshot-settings.gradle.kts[] ---- -provided you add the following lines in the `settings.gradle` file (or `settings.gradle.kts` in Kotlin): +The plugin can then be applied using the `plugins` block: [source,groovy,indent=0,subs="verbatim,attributes",role="primary"] .Groovy ---- -include::../gradle/getting-started/snapshot-settings.gradle[] +include::../gradle/getting-started/apply-plugin-release.gradle[] ---- [source,kotlin,indent=0,subs="verbatim,attributes",role="secondary"] .Kotlin ---- -include::../gradle/getting-started/snapshot-settings.gradle.kts[] +include::../gradle/getting-started/apply-plugin-release.gradle.kts[] ---- endif::[] diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/asciidoc/managing-dependencies.adoc b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/asciidoc/managing-dependencies.adoc index 5cbfd793cc36..cb35083696fb 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/asciidoc/managing-dependencies.adoc +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/asciidoc/managing-dependencies.adoc @@ -121,13 +121,12 @@ include::../gradle/managing-dependencies/configure-bom.gradle.kts[tags=configure ---- -The Kotlin code above is a bit awkward. That's because we're using the imperative way of applying -the dependency management plugin. +The Kotlin code above is a bit awkward. That's because we're using the imperative way of +applying the dependency management plugin. -We can make the code less awkward by applying the plugin from -the root parent project, or by using the `plugins` block as we're doing for the spring boot plugin. -The downside of this method, though, is that it forces us to specify the version of the -dependency management plugin, even though it's a dependency of the spring boot plugin: +We can make the code less awkward by applying the plugin from the root parent project, or +by using the `plugins` block as we're doing for the Spring Boot plugin. A downside of this +method is that it forces us to specify the version of the dependency management plugin: [source,kotlin,indent=0,subs="verbatim,attributes"] ---- diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/docs/GettingStartedDocumentationTests.java b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/docs/GettingStartedDocumentationTests.java index fb63e096afef..81179633015d 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/docs/GettingStartedDocumentationTests.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/docs/GettingStartedDocumentationTests.java @@ -20,6 +20,7 @@ import org.junit.Test; import org.junit.runner.RunWith; +import org.springframework.boot.gradle.junit.GradleMultiDslSuite; import org.springframework.boot.gradle.testkit.GradleBuild; /** @@ -34,15 +35,13 @@ public class GettingStartedDocumentationTests { @Rule public GradleBuild gradleBuild; - public DSL dsl; - // NOTE: We can't run any `apply-plugin` tests because during a release the // jar won't be there @Test public void typicalPluginsAppliesExceptedPlugins() { - this.gradleBuild.script("src/main/gradle/getting-started/typical-plugins" - + this.dsl.getExtension()).build("verify"); + this.gradleBuild.script("src/main/gradle/getting-started/typical-plugins") + .build("verify"); } } diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/docs/IntegratingWithActuatorDocumentationTests.java b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/docs/IntegratingWithActuatorDocumentationTests.java index a8c15e650c36..6c8887ccb2a8 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/docs/IntegratingWithActuatorDocumentationTests.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/docs/IntegratingWithActuatorDocumentationTests.java @@ -25,6 +25,7 @@ import org.junit.Test; import org.junit.runner.RunWith; +import org.springframework.boot.gradle.junit.GradleMultiDslSuite; import org.springframework.boot.gradle.testkit.GradleBuild; import static org.assertj.core.api.Assertions.assertThat; @@ -41,13 +42,10 @@ public class IntegratingWithActuatorDocumentationTests { @Rule public GradleBuild gradleBuild; - public DSL dsl; - @Test public void basicBuildInfo() throws IOException { this.gradleBuild - .script("src/main/gradle/integrating-with-actuator/build-info-basic" - + this.dsl.getExtension()) + .script("src/main/gradle/integrating-with-actuator/build-info-basic") .build("bootBuildInfo"); assertThat(new File(this.gradleBuild.getProjectDir(), "build/resources/main/META-INF/build-info.properties")).isFile(); @@ -56,8 +54,7 @@ public void basicBuildInfo() throws IOException { @Test public void buildInfoCustomValues() throws IOException { this.gradleBuild.script( - "src/main/gradle/integrating-with-actuator/build-info-custom-values" - + this.dsl.getExtension()) + "src/main/gradle/integrating-with-actuator/build-info-custom-values") .build("bootBuildInfo"); File file = new File(this.gradleBuild.getProjectDir(), "build/resources/main/META-INF/build-info.properties"); @@ -72,8 +69,7 @@ public void buildInfoCustomValues() throws IOException { @Test public void buildInfoAdditional() throws IOException { this.gradleBuild - .script("src/main/gradle/integrating-with-actuator/build-info-additional" - + this.dsl.getExtension()) + .script("src/main/gradle/integrating-with-actuator/build-info-additional") .build("bootBuildInfo"); File file = new File(this.gradleBuild.getProjectDir(), "build/resources/main/META-INF/build-info.properties"); diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/docs/ManagingDependenciesDocumentationTests.java b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/docs/ManagingDependenciesDocumentationTests.java index 7ead0d8e7ea3..ab93a816076a 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/docs/ManagingDependenciesDocumentationTests.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/docs/ManagingDependenciesDocumentationTests.java @@ -16,10 +16,13 @@ package org.springframework.boot.gradle.docs; +import org.junit.Assume; import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; +import org.springframework.boot.gradle.junit.GradleMultiDslSuite; +import org.springframework.boot.gradle.testkit.Dsl; import org.springframework.boot.gradle.testkit.GradleBuild; import static org.assertj.core.api.Assertions.assertThat; @@ -36,41 +39,34 @@ public class ManagingDependenciesDocumentationTests { @Rule public GradleBuild gradleBuild; - public DSL dsl; - @Test public void dependenciesExampleEvaluatesSuccessfully() { - this.gradleBuild.script("src/main/gradle/managing-dependencies/dependencies" - + this.dsl.getExtension()).build(); + this.gradleBuild.script("src/main/gradle/managing-dependencies/dependencies") + .build(); } @Test public void customManagedVersions() { - assertThat( - this.gradleBuild - .script("src/main/gradle/managing-dependencies/custom-version" - + this.dsl.getExtension()) - .build("slf4jVersion").getOutput()).contains("1.7.20"); + assertThat(this.gradleBuild + .script("src/main/gradle/managing-dependencies/custom-version") + .build("slf4jVersion").getOutput()).contains("1.7.20"); } @Test public void dependencyManagementInIsolation() { assertThat(this.gradleBuild - .script("src/main/gradle/managing-dependencies/configure-bom" - + this.dsl.getExtension()) + .script("src/main/gradle/managing-dependencies/configure-bom") .build("dependencyManagement").getOutput()) .contains("org.springframework.boot:spring-boot-starter "); } @Test public void dependencyManagementInIsolationWithPluginsBlock() { - if (this.dsl == DSL.KOTLIN) { - assertThat(this.gradleBuild.script( - "src/main/gradle/managing-dependencies/configure-bom-with-plugins" - + this.dsl.getExtension()) - .build("dependencyManagement").getOutput()) - .contains("org.springframework.boot:spring-boot-starter "); - } + Assume.assumeTrue(this.gradleBuild.getDsl() == Dsl.KOTLIN); + assertThat(this.gradleBuild.script( + "src/main/gradle/managing-dependencies/configure-bom-with-plugins") + .build("dependencyManagement").getOutput()) + .contains("org.springframework.boot:spring-boot-starter "); } } diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/docs/PackagingDocumentationTests.java b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/docs/PackagingDocumentationTests.java index d19ca09f3d3d..5a14062d2480 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/docs/PackagingDocumentationTests.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/docs/PackagingDocumentationTests.java @@ -27,6 +27,8 @@ import org.junit.Test; import org.junit.runner.RunWith; +import org.springframework.boot.gradle.junit.GradleMultiDslSuite; +import org.springframework.boot.gradle.testkit.Dsl; import org.springframework.boot.gradle.testkit.GradleBuild; import org.springframework.util.FileCopyUtils; @@ -44,18 +46,17 @@ public class PackagingDocumentationTests { @Rule public GradleBuild gradleBuild; - public DSL dsl; + public Dsl dsl; @Test public void warContainerDependencyEvaluatesSuccessfully() { - this.gradleBuild.script("src/main/gradle/packaging/war-container-dependency" - + this.dsl.getExtension()).build(); + this.gradleBuild.script("src/main/gradle/packaging/war-container-dependency") + .build(); } @Test public void bootJarMainClass() throws IOException { - this.gradleBuild.script( - "src/main/gradle/packaging/boot-jar-main-class" + this.dsl.getExtension()) + this.gradleBuild.script("src/main/gradle/packaging/boot-jar-main-class") .build("bootJar"); File file = new File(this.gradleBuild.getProjectDir(), "build/libs/" + this.gradleBuild.getProjectDir().getName() + ".jar"); @@ -68,8 +69,8 @@ public void bootJarMainClass() throws IOException { @Test public void bootJarManifestMainClass() throws IOException { - this.gradleBuild.script("src/main/gradle/packaging/boot-jar-manifest-main-class" - + this.dsl.getExtension()).build("bootJar"); + this.gradleBuild.script("src/main/gradle/packaging/boot-jar-manifest-main-class") + .build("bootJar"); File file = new File(this.gradleBuild.getProjectDir(), "build/libs/" + this.gradleBuild.getProjectDir().getName() + ".jar"); assertThat(file).isFile(); @@ -81,8 +82,8 @@ public void bootJarManifestMainClass() throws IOException { @Test public void applicationPluginMainClass() throws IOException { - this.gradleBuild.script("src/main/gradle/packaging/application-plugin-main-class" - + this.dsl.getExtension()).build("bootJar"); + this.gradleBuild.script("src/main/gradle/packaging/application-plugin-main-class") + .build("bootJar"); File file = new File(this.gradleBuild.getProjectDir(), "build/libs/" + this.gradleBuild.getProjectDir().getName() + ".jar"); assertThat(file).isFile(); @@ -94,8 +95,8 @@ public void applicationPluginMainClass() throws IOException { @Test public void springBootDslMainClass() throws IOException { - this.gradleBuild.script("src/main/gradle/packaging/spring-boot-dsl-main-class" - + this.dsl.getExtension()).build("bootJar"); + this.gradleBuild.script("src/main/gradle/packaging/spring-boot-dsl-main-class") + .build("bootJar"); File file = new File(this.gradleBuild.getProjectDir(), "build/libs/" + this.gradleBuild.getProjectDir().getName() + ".jar"); assertThat(file).isFile(); @@ -109,8 +110,8 @@ public void springBootDslMainClass() throws IOException { public void bootWarIncludeDevtools() throws IOException { new File(this.gradleBuild.getProjectDir(), "spring-boot-devtools-1.2.3.RELEASE.jar").createNewFile(); - this.gradleBuild.script("src/main/gradle/packaging/boot-war-include-devtools" - + this.dsl.getExtension()).build("bootWar"); + this.gradleBuild.script("src/main/gradle/packaging/boot-war-include-devtools") + .build("bootWar"); File file = new File(this.gradleBuild.getProjectDir(), "build/libs/" + this.gradleBuild.getProjectDir().getName() + ".war"); assertThat(file).isFile(); @@ -122,8 +123,8 @@ public void bootWarIncludeDevtools() throws IOException { @Test public void bootJarRequiresUnpack() throws IOException { - this.gradleBuild.script("src/main/gradle/packaging/boot-jar-requires-unpack" - + this.dsl.getExtension()).build("bootJar"); + this.gradleBuild.script("src/main/gradle/packaging/boot-jar-requires-unpack") + .build("bootJar"); File file = new File(this.gradleBuild.getProjectDir(), "build/libs/" + this.gradleBuild.getProjectDir().getName() + ".jar"); assertThat(file).isFile(); @@ -136,8 +137,9 @@ public void bootJarRequiresUnpack() throws IOException { @Test public void bootJarIncludeLaunchScript() throws IOException { - this.gradleBuild.script("src/main/gradle/packaging/boot-jar-include-launch-script" - + this.dsl.getExtension()).build("bootJar"); + this.gradleBuild + .script("src/main/gradle/packaging/boot-jar-include-launch-script") + .build("bootJar"); File file = new File(this.gradleBuild.getProjectDir(), "build/libs/" + this.gradleBuild.getProjectDir().getName() + ".jar"); assertThat(file).isFile(); @@ -148,8 +150,7 @@ public void bootJarIncludeLaunchScript() throws IOException { @Test public void bootJarLaunchScriptProperties() throws IOException { this.gradleBuild - .script("src/main/gradle/packaging/boot-jar-launch-script-properties" - + this.dsl.getExtension()) + .script("src/main/gradle/packaging/boot-jar-launch-script-properties") .build("bootJar"); File file = new File(this.gradleBuild.getProjectDir(), "build/libs/" + this.gradleBuild.getProjectDir().getName() + ".jar"); @@ -164,8 +165,8 @@ public void bootJarCustomLaunchScript() throws IOException { "src/custom.script"); customScriptFile.getParentFile().mkdirs(); FileCopyUtils.copy("custom", new FileWriter(customScriptFile)); - this.gradleBuild.script("src/main/gradle/packaging/boot-jar-custom-launch-script" - + this.dsl.getExtension()).build("bootJar"); + this.gradleBuild.script("src/main/gradle/packaging/boot-jar-custom-launch-script") + .build("bootJar"); File file = new File(this.gradleBuild.getProjectDir(), "build/libs/" + this.gradleBuild.getProjectDir().getName() + ".jar"); assertThat(file).isFile(); @@ -174,8 +175,8 @@ public void bootJarCustomLaunchScript() throws IOException { @Test public void bootWarPropertiesLauncher() throws IOException { - this.gradleBuild.script("src/main/gradle/packaging/boot-war-properties-launcher" - + this.dsl.getExtension()).build("bootWar"); + this.gradleBuild.script("src/main/gradle/packaging/boot-war-properties-launcher") + .build("bootWar"); File file = new File(this.gradleBuild.getProjectDir(), "build/libs/" + this.gradleBuild.getProjectDir().getName() + ".war"); assertThat(file).isFile(); @@ -187,8 +188,7 @@ public void bootWarPropertiesLauncher() throws IOException { @Test public void bootJarAndJar() { - this.gradleBuild.script( - "src/main/gradle/packaging/boot-jar-and-jar" + this.dsl.getExtension()) + this.gradleBuild.script("src/main/gradle/packaging/boot-jar-and-jar") .build("assemble"); File jar = new File(this.gradleBuild.getProjectDir(), "build/libs/" + this.gradleBuild.getProjectDir().getName() + ".jar"); diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/docs/PublishingDocumentationTests.java b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/docs/PublishingDocumentationTests.java index 3e5eb2cb3da7..7a796d4c6749 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/docs/PublishingDocumentationTests.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/docs/PublishingDocumentationTests.java @@ -22,6 +22,7 @@ import org.junit.Test; import org.junit.runner.RunWith; +import org.springframework.boot.gradle.junit.GradleMultiDslSuite; import org.springframework.boot.gradle.testkit.GradleBuild; import static org.assertj.core.api.Assertions.assertThat; @@ -38,21 +39,16 @@ public class PublishingDocumentationTests { @Rule public GradleBuild gradleBuild; - public DSL dsl; - @Test public void mavenUpload() throws IOException { - assertThat(this.gradleBuild - .script("src/main/gradle/publishing/maven" + this.dsl.getExtension()) + assertThat(this.gradleBuild.script("src/main/gradle/publishing/maven") .build("deployerRepository").getOutput()) .contains("https://repo.example.com"); } @Test public void mavenPublish() throws IOException { - assertThat(this.gradleBuild - .script("src/main/gradle/publishing/maven-publish" - + this.dsl.getExtension()) + assertThat(this.gradleBuild.script("src/main/gradle/publishing/maven-publish") .build("publishingConfiguration").getOutput()) .contains("MavenPublication") .contains("https://repo.example.com"); diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/docs/RunningDocumentationTests.java b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/docs/RunningDocumentationTests.java index 97ba9694bea5..cfb543ccf9ab 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/docs/RunningDocumentationTests.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/docs/RunningDocumentationTests.java @@ -23,6 +23,7 @@ import org.junit.Test; import org.junit.runner.RunWith; +import org.springframework.boot.gradle.junit.GradleMultiDslSuite; import org.springframework.boot.gradle.testkit.GradleBuild; import static org.assertj.core.api.Assertions.assertThat; @@ -39,12 +40,9 @@ public class RunningDocumentationTests { @Rule public GradleBuild gradleBuild; - public DSL dsl; - @Test public void bootRunMain() throws IOException { - assertThat(this.gradleBuild - .script("src/main/gradle/running/boot-run-main" + this.dsl.getExtension()) + assertThat(this.gradleBuild.script("src/main/gradle/running/boot-run-main") .build("configuredMainClass").getOutput()) .contains("com.example.ExampleApplication"); } @@ -52,8 +50,7 @@ public void bootRunMain() throws IOException { @Test public void applicationPluginMainClassName() { assertThat(this.gradleBuild - .script("src/main/gradle/running/application-plugin-main-class-name" - + this.dsl.getExtension()) + .script("src/main/gradle/running/application-plugin-main-class-name") .build("configuredMainClass").getOutput()) .contains("com.example.ExampleApplication"); } @@ -61,8 +58,7 @@ public void applicationPluginMainClassName() { @Test public void springBootDslMainClassName() throws IOException { assertThat(this.gradleBuild - .script("src/main/gradle/running/spring-boot-dsl-main-class-name" - + this.dsl.getExtension()) + .script("src/main/gradle/running/spring-boot-dsl-main-class-name") .build("configuredMainClass").getOutput()) .contains("com.example.ExampleApplication"); } @@ -70,8 +66,7 @@ public void springBootDslMainClassName() throws IOException { @Test public void bootRunSourceResources() throws IOException { assertThat(this.gradleBuild - .script("src/main/gradle/running/boot-run-source-resources" - + this.dsl.getExtension()) + .script("src/main/gradle/running/boot-run-source-resources") .build("configuredClasspath").getOutput()) .contains(new File("src/main/resources").getPath()); } diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/docs/GradleMultiDslSuite.java b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/junit/GradleMultiDslSuite.java similarity index 78% rename from spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/docs/GradleMultiDslSuite.java rename to spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/junit/GradleMultiDslSuite.java index e35c7c9d259a..dc0e3e6ffc14 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/docs/GradleMultiDslSuite.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/junit/GradleMultiDslSuite.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.boot.gradle.docs; +package org.springframework.boot.gradle.junit; import java.util.ArrayList; import java.util.List; @@ -26,15 +26,16 @@ import org.junit.runners.model.FrameworkMethod; import org.junit.runners.model.InitializationError; +import org.springframework.boot.gradle.testkit.Dsl; import org.springframework.boot.gradle.testkit.GradleBuild; /** * Custom {@link Suite} that runs tests against the Groovy and the Kotlin DSLs. Test - * classes using the suite must have a public {@link DSL} field named {@code dsl} and a - * public {@link GradleBuild} field named {@code gradleBuild} and annotated with - * {@link Rule} + * classes using the suite must have a public {@link GradleBuild} field named + * {@code gradleBuild} and annotated with {@link Rule}. * * @author Jean-Baptiste Nizet + * @author Andy Wilkinson */ public final class GradleMultiDslSuite extends Suite { @@ -44,9 +45,8 @@ public GradleMultiDslSuite(Class clazz) throws InitializationError { private static List createRunners(Class clazz) throws InitializationError { List runners = new ArrayList<>(); - runners.add(new GradleDslClassRunner(clazz, new GradleBuild(), DSL.GROOVY)); - runners.add(new GradleDslClassRunner(clazz, - new GradleBuild().withMinimalGradleVersionForKotlinDSL(), DSL.KOTLIN)); + runners.add(new GradleDslClassRunner(clazz, new GradleBuild(Dsl.GROOVY))); + runners.add(new GradleDslClassRunner(clazz, new GradleBuild(Dsl.KOTLIN))); return runners; } @@ -54,13 +54,10 @@ private static final class GradleDslClassRunner extends BlockJUnit4ClassRunner { private final GradleBuild gradleBuild; - private final DSL dsl; - - private GradleDslClassRunner(Class klass, GradleBuild gradleBuild, DSL dsl) + private GradleDslClassRunner(Class klass, GradleBuild gradleBuild) throws InitializationError { super(klass); this.gradleBuild = gradleBuild; - this.dsl = dsl; } @Override @@ -72,12 +69,11 @@ protected Object createTest() throws Exception { private void configureTest(Object test) throws Exception { test.getClass().getField("gradleBuild").set(test, this.gradleBuild); - test.getClass().getField("dsl").set(test, this.dsl); } @Override protected String getName() { - return this.dsl.getName() + " DSL"; + return this.gradleBuild.getDsl().getName() + " DSL"; } @Override diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/docs/DSL.java b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/testkit/Dsl.java similarity index 89% rename from spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/docs/DSL.java rename to spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/testkit/Dsl.java index 8b30d1ff02e8..974f308389b8 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/docs/DSL.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/testkit/Dsl.java @@ -13,12 +13,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.boot.gradle.docs; +package org.springframework.boot.gradle.testkit; /** * The DSLs supported by Gradle and demonstrated in the documentation samples */ -public enum DSL { +public enum Dsl { GROOVY("Groovy", ".gradle"), KOTLIN("Kotlin", ".gradle.kts"); @@ -26,7 +26,7 @@ public enum DSL { private final String extension; - DSL(String name, String extension) { + Dsl(String name, String extension) { this.name = name; this.extension = extension; } @@ -41,7 +41,7 @@ public String getName() { /** * Gets the file extension of build scripts (starting with a dot) */ - public String getExtension() { + String getExtension() { return this.extension; } diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/testkit/GradleBuild.java b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/testkit/GradleBuild.java index a571ea325012..1622672eec0b 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/testkit/GradleBuild.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/testkit/GradleBuild.java @@ -65,12 +65,26 @@ public class GradleBuild implements TestRule { private final TemporaryFolder temp = new TemporaryFolder(); + private final Dsl dsl; + private File projectDir; private String script; private String gradleVersion; + public GradleBuild() { + this(Dsl.GROOVY); + } + + public GradleBuild(Dsl dsl) { + this.dsl = dsl; + } + + public Dsl getDsl() { + return this.dsl; + } + @Override public Statement apply(Statement base, Description description) { URL scriptUrl = findDefaultScript(description); @@ -103,7 +117,8 @@ private URL findDefaultScript(Description description) { private URL getScriptForTestMethod(Description description) { String name = description.getTestClass().getSimpleName() + "-" - + removeGradleVersion(description.getMethodName()) + ".gradle"; + + removeGradleVersion(description.getMethodName()) + + this.dsl.getExtension(); return description.getTestClass().getResource(name); } @@ -112,7 +127,7 @@ private String removeGradleVersion(String methodName) { } private URL getScriptForTestClass(Class testClass) { - return testClass.getResource(testClass.getSimpleName() + ".gradle"); + return testClass.getResource(testClass.getSimpleName() + this.dsl.getExtension()); } private void before() throws IOException { @@ -142,7 +157,8 @@ private String pathOfJarContaining(Class type) { } public GradleBuild script(String script) { - this.script = script; + this.script = script.endsWith(this.dsl.getExtension()) ? script + : script + this.dsl.getExtension(); return this; } @@ -169,19 +185,20 @@ public GradleRunner prepareRunner(String... arguments) throws IOException { .replace("{version}", getBootVersion()) .replace("{dependency-management-plugin-version}", getDependencyManagementPluginVersion()); - boolean isKotlin = this.script.endsWith(".kts"); - String extension = isKotlin ? ".kts" : ""; - FileCopyUtils.copy(scriptContent, - new FileWriter(new File(this.projectDir, "build.gradle" + extension))); + FileCopyUtils.copy(scriptContent, new FileWriter( + new File(this.projectDir, "build" + this.dsl.getExtension()))); GradleRunner gradleRunner = GradleRunner.create().withProjectDir(this.projectDir) .withPluginClasspath(pluginClasspath()); - if (!isKotlin) { + if (this.dsl != Dsl.KOTLIN) { // see https://github.com/gradle/gradle/issues/6862 gradleRunner.withDebug(true); } if (this.gradleVersion != null) { gradleRunner.withGradleVersion(this.gradleVersion); } + else if (this.dsl == Dsl.KOTLIN) { + gradleRunner.withGradleVersion("4.10.2"); + } List allArguments = new ArrayList<>(); allArguments.add("-PbootVersion=" + getBootVersion()); allArguments.add("--stacktrace"); @@ -202,11 +219,6 @@ public GradleBuild gradleVersion(String version) { return this; } - public GradleBuild withMinimalGradleVersionForKotlinDSL() { - this.gradleVersion = "4.10.2"; - return this; - } - public String getGradleVersion() { return this.gradleVersion; }