How can I run another gradle script from gradle. I have multiple gradle scripts to run tests under <root_project>/test
directory. The <root_project>/build.gradle
is invoked with the name of the test gradle file to be run. For example
gradle run_test -PtestFile=foobar
This should run <root_project>/test/foobar.gradle
(default tasks of it)
What I'm currently doing is invoking project.exec
in the run_test
task. This works but now I need to pass the project properties from the gradle process running run_test to the one which runs foobar.gradle
How can I do this ? Is there a more gradle-integrated way to run a gradle script from another, passing all the required info to the child gradle script ?
I do something similar where a "construct" task in one gradle hands off to a "perform" task in another gradle file in a dir it has created (called the artefact), and it passes through all the project properties through too.
Here's the relevant code for the handoff:
def gradleTask = "yourTaskToEventuallyRun"
def artefactBuild = project.tasks.create([name: "artefactBuild_$gradleTask", type: GradleBuild])
artefactBuild.buildFile = project.file("${artefactDir}/build.gradle")
artefactBuild.tasks = [gradleTask]
// inject all parameters passed to this build through to artefact build
def artefactProjectProperties = artefactBuild.startParameter.projectProperties
def currentProjectProperties = project.gradle.startParameter.projectProperties
artefactProjectProperties << currentProjectProperties
// you can add more here
// artefactProjectProperties << [someKey: someValue]
artefactBuild.execute()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With