Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run gradle script from gradle

Tags:

gradle

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 ?

like image 911
Sundeep Gupta Avatar asked Oct 20 '14 05:10

Sundeep Gupta


1 Answers

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()
like image 183
Mark Fisher Avatar answered Oct 21 '22 20:10

Mark Fisher