Gradle¶
Properties¶
dir¶
A temporary directory unique for each test, in which the Gradle files are created.
Example¶
Print the directory:
properties¶
suspend fun Gradle.properties(text: String)
Helper function to write the gradle.properties file.
Example¶
val Gradle.properties: Prepared<Path>
Accessor for the gradle.properties file.
Example¶
rootProject¶
val rootProject: Project
Accessor for the files of the root project.
Example¶
Create the root build.gradle.kts file:
test("Create the root build.gradle.kts file") {
gradle.rootProject.buildKts("""
println("Configuring the project")
""".trimIndent()
}
See also
-
Gradle.project: Access another project -
Gradle.runner: Execute the test and check the outputs
settingsGroovy¶
suspend fun Gradle.settingsGroovy(text: String)
Helper function to write the settings.gradle file.
Example¶
test("Create a groovy settings file") {
gradle.settingsGroovy("""
println "Loading the settings…"
""".trimIndent())
}
See also
-
settingsKts: Kotlin equivalent -
buildGroovy: Build script file
val Gradle.settingsGroovy: Prepared<Path>
Accessor for the settings.gradle file.
Example¶
See also
-
settingsKts: Kotlin equivalent -
buildGroovy: Build script file
settingsKts¶
suspend fun Gradle.settingsKts(text: String)
Helper function to write the settings.gradle.kts file.
Example¶
test("Create a Kotlin DSL settings file") {
gradle.settingsKts("""
println("Loading the settings…")
""".trimIndent())
}
See also
-
settingsGroovy: Groovy equivalent -
buildKts: Build script file
val Gradle.settingsKts: Prepared<Path>
Accessor for the settings.gradle.kts file.
Example¶
See also
-
settingsGroovy: Groovy equivalent -
buildKts: Build script file
Functions¶
project¶
Accessor for the files of a project, given its path.
Example¶
Create the modules/foo/build.gradle file:
test("Configure the :modules:foo project") {
gradle.project("modules/foo").buildGroovy("""
println "Configuring the project!"
""".trimIndent())
}
See also
-
Gradle.rootProject: Access the root project -
Gradle.runner: Execute the test and check the outputs
runner¶
suspend fun runner(): GradleRunner
Instantiates a GradleRunner in dir.
Examples¶
test("Create the root build.gradle.kts file") {
gradle.rootProject.buildKts("""
tasks.register("print") {
doLast {
println("Configuring the project")
}
}
""".trimIndent()
val result = gradle.runner()
.withPluginClasspath()
.withArguments("print")
.build()
result.output shouldContain "Configuring the project"
}
See also
-
GradleRunner.withPluginClasspath: When writing tests for a plugin, automatically adds it to the executed Gradle instance
-
GradleRunner.withArguments: Specify which tasks should be executed
-
GradleRunner.build: Executes the build, expecting a success
-
GradleRunner.buildAndFail: Executes the build, expecting a failure