Skip to content

Commit

Permalink
Polish "Add Kotlin DSL examples to Gradle Plugin's documentation"
Browse files Browse the repository at this point in the history
  • Loading branch information
wilkinsona committed Oct 5, 2018
1 parent 5ed6c0d commit a3d2f3f
Show file tree
Hide file tree
Showing 11 changed files with 122 additions and 127 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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::[]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
----
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -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");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
Expand All @@ -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");
Expand All @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 ");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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");
Expand All @@ -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();
Expand All @@ -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();
Expand All @@ -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();
Expand All @@ -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();
Expand All @@ -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();
Expand All @@ -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();
Expand All @@ -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");
Expand All @@ -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();
Expand All @@ -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();
Expand All @@ -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");
Expand Down
Loading

0 comments on commit a3d2f3f

Please sign in to comment.