Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
a3d2f3f5
Commit
a3d2f3f5
authored
Oct 05, 2018
by
Andy Wilkinson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Polish "Add Kotlin DSL examples to Gradle Plugin's documentation"
Closes gh-14585
parent
5ed6c0d1
Changes
11
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
122 additions
and
127 deletions
+122
-127
getting-started.adoc
...boot-gradle-plugin/src/main/asciidoc/getting-started.adoc
+25
-19
managing-dependencies.adoc
...radle-plugin/src/main/asciidoc/managing-dependencies.adoc
+5
-6
GettingStartedDocumentationTests.java
...rk/boot/gradle/docs/GettingStartedDocumentationTests.java
+3
-4
IntegratingWithActuatorDocumentationTests.java
...radle/docs/IntegratingWithActuatorDocumentationTests.java
+4
-8
ManagingDependenciesDocumentationTests.java
...t/gradle/docs/ManagingDependenciesDocumentationTests.java
+14
-18
PackagingDocumentationTests.java
...amework/boot/gradle/docs/PackagingDocumentationTests.java
+25
-25
PublishingDocumentationTests.java
...mework/boot/gradle/docs/PublishingDocumentationTests.java
+3
-7
RunningDocumentationTests.java
...framework/boot/gradle/docs/RunningDocumentationTests.java
+5
-10
GradleMultiDslSuite.java
...pringframework/boot/gradle/junit/GradleMultiDslSuite.java
+9
-13
Dsl.java
...est/java/org/springframework/boot/gradle/testkit/Dsl.java
+4
-4
GradleBuild.java
.../org/springframework/boot/gradle/testkit/GradleBuild.java
+25
-13
No files found.
spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/asciidoc/getting-started.adoc
View file @
a3d2f3f5
...
...
@@ -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::[]
...
...
spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/asciidoc/managing-dependencies.adoc
View file @
a3d2f3f5
...
...
@@ -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"]
----
...
...
spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/docs/GettingStartedDocumentationTests.java
View file @
a3d2f3f5
...
...
@@ -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"
);
}
}
spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/docs/IntegratingWithActuatorDocumentationTests.java
View file @
a3d2f3f5
...
...
@@ -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"
);
...
...
spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/docs/ManagingDependenciesDocumentationTests.java
View file @
a3d2f3f5
...
...
@@ -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 "
);
}
}
spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/docs/PackagingDocumentationTests.java
View file @
a3d2f3f5
...
...
@@ -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
D
SL
dsl
;
public
D
sl
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"
);
...
...
spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/docs/PublishingDocumentationTests.java
View file @
a3d2f3f5
...
...
@@ -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"
);
...
...
spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/docs/RunningDocumentationTests.java
View file @
a3d2f3f5
...
...
@@ -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
());
}
...
...
spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/
docs
/GradleMultiDslSuite.java
→
spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/
junit
/GradleMultiDslSuite.java
View file @
a3d2f3f5
...
...
@@ -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
...
...
spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/
docs/DSL
.java
→
spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/
testkit/Dsl
.java
View file @
a3d2f3f5
...
...
@@ -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
D
SL
{
public
enum
D
sl
{
GROOVY
(
"Groovy"
,
".gradle"
),
KOTLIN
(
"Kotlin"
,
".gradle.kts"
);
...
...
@@ -26,7 +26,7 @@ public enum DSL {
private
final
String
extension
;
D
SL
(
String
name
,
String
extension
)
{
D
sl
(
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
;
}
...
...
spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/testkit/GradleBuild.java
View file @
a3d2f3f5
...
...
@@ -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
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment