I am trying to write an integration test for one of my plugins. The plugin adds functionality to create a jar of all the .class files of all subprojects. I am trying to use GradleLauncher.newInstance(startParameter) to run the build, but it seems to not be adding the sub projects to the root project it is running the tasks against. Here is the settings.gradle file of the project I am launching:
new File("$settingsDir/components/").eachDir {
include it.name
}
rootProject.name = "jumboJar"
println rootProject.children
rootProject.children.each { project ->
String projectDirName = "components/${project.name}"
project.projectDir = new File(settingsDir, projectDirName)
project.buildFileName = "${project.name}.gradle"
}
And I am launching it like this:
def project = ProjectBuilder.builder().withProjectDir(projectDir).build()
def runTasks(Map<String, Object> args, List<String> tasks) {
def startParameter = project.gradle.startParameter.newBuild()
startParameter.setGradleUserHomeDir(new File('userHome'));
startParameter.projectDir = project.projectDir
if (args.buildScript) {
startParameter.buildFile = new File(project.projectDir, args.buildScript)
}
if (args.settingsFile) {
startParameter.settingsFile = new File(project.projectDir, args.settingsFile)
}
startParameter.taskNames = tasks
def launcher = GradleLauncher.newInstance(startParameter)
println "BEFORE LAUNCH"
def result = launcher.run()
println "AFTER LAUNCH"
result.rethrowFailure()
}
When I run the ‘:clean, :projects’ tasks, I get the following output:
BEFORE LAUNCH
[:sub1, :sub2] //println from settings.gradle file
:clean
UP-TO-DATE
:projects
------------------------------------------------------------
Root project
------------------------------------------------------------
Root project 'jumboJar'
No sub-projects
To see a list of the tasks of a project, run
gradle
<project-path>:tasks
For example, try running
gradle
:tasks
BUILD SUCCESSFUL
Total time: 3.554 secs
AFTER LAUNCH
So you can see from the println statement from the settings file that it is picking up the subprojects of the build and adding it to a Project, but it seems that when it runs the tasks it is against a different object because it says it has no subprojects.
Thank you,
Jeremy