Commit a3d2f3f5 authored by Andy Wilkinson's avatar Andy Wilkinson

Polish "Add Kotlin DSL examples to Gradle Plugin's documentation"

Closes gh-14585
parent 5ed6c0d1
......@@ -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::[]
......
......@@ -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"]
----
......
......@@ -20,6 +20,7 @@ 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.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");
}
}
......@@ -25,6 +25,7 @@ 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.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 class IntegratingWithActuatorDocumentationTests {
@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 class IntegratingWithActuatorDocumentationTests {
@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");
......
......@@ -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 ");
}
}
......@@ -27,6 +27,8 @@ 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 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 class PackagingDocumentationTests {
@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 class PackagingDocumentationTests {
@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 class PackagingDocumentationTests {
@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 class PackagingDocumentationTests {
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 class PackagingDocumentationTests {
@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 class PackagingDocumentationTests {
@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 class PackagingDocumentationTests {
@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 class PackagingDocumentationTests {
"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 class PackagingDocumentationTests {
@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 class PackagingDocumentationTests {
@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");
......
......@@ -22,6 +22,7 @@ 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.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");
......
......@@ -23,6 +23,7 @@ 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.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 class RunningDocumentationTests {
@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 class RunningDocumentationTests {
@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 class RunningDocumentationTests {
@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());
}
......
......@@ -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.Suite;
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 final class GradleMultiDslSuite extends Suite {
private static List<Runner> createRunners(Class<?> clazz) throws InitializationError {
List<Runner> 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 @@ public final class GradleMultiDslSuite extends Suite {
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 @@ public final class GradleMultiDslSuite extends Suite {
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
......
......@@ -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 enum DSL {
/**
* Gets the file extension of build scripts (starting with a dot)
*/
public String getExtension() {
String getExtension() {
return this.extension;
}
......
......@@ -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 @@ public class GradleBuild implements TestRule {
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 @@ public class GradleBuild implements TestRule {
}
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 @@ public class GradleBuild implements TestRule {
}
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 class GradleBuild implements TestRule {
.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<String> allArguments = new ArrayList<>();
allArguments.add("-PbootVersion=" + getBootVersion());
allArguments.add("--stacktrace");
......@@ -202,11 +219,6 @@ public class GradleBuild implements TestRule {
return this;
}
public GradleBuild withMinimalGradleVersionForKotlinDSL() {
this.gradleVersion = "4.10.2";
return this;
}
public String getGradleVersion() {
return this.gradleVersion;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment