This plugin allows you to script Gradle executions as steps and then collect the output from those steps. It is particularly useful in the crafting of documentation related to Gradle. It requires requires Gradle 2.14+ or later.
Bootstrap
GradleRunner is available in the Gradle Plugins repository.
To use it, add the appropriate plugin to the plugins
block.
plugins {
id 'org.ysb33r.gradlerunner' version '1.1' (1)
}
1 | Use the gradlerunner to easily execute independent steps of GradleRunner . |
When your setup is more complex and the plugins block does not work use the following instead
buildscript {
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath 'org.ysb33r.gradle:gradle-runner:1.1'
}
}
apply plugin: 'org.ysb33r.gradlerunner'
The org.ysb33r.gradlerunner
plugin adds a default task called gradleRunner
which is of type GradleRunnerSteps
. This task allows people to run specific Gradle steps interleaved via other actions such as copying files..
Steps
Steps are added via the step
keyword. Each step has a name which can later be used to extract information after execution.
gradleRunner {
step 'a simple closure', { (1)
new File(workingDir,'build.gradle').text = '/* empty build file */'
new File(reportsDir,'foo.txt').text = 'output to report directory' (2)
}
step 'running gradle', 'tasks', '--all' (3)
failingStep 'this gradle will fail', 'non-existing-task' (4)
}
1 | A step can be a closure or an Action . |
2 | Every step will have an unique directory for dropping files, |
3 | A step can be a Gradle execution. Supply all command-line parameters after the name. A Gradle execution will drop out.txt and err.txt in the report directory. |
4 | A step can also be a Gradle execution that is known to fail. |
After execution use gradleRunner.getStepReportDir(STEP_NAME)
to obtain the reporting directory for a step.