I am using a project with a Convention Plugin to apply common logic between submodules. The project structure looks like this:
my-project/
├── buildSrc/
│ └── .../java-common.gradle # Here the 'java' plugin is applied
├── module-1/
│ └── build.gradle # Here the 'java-common' convention is applied
└── module-1/
└── build.gradle # Here the 'java-common' convention is applied
This build succeeds fine locally. However, our CI system applies an init script aggregates SourceSets:
rootProject {
// Define variable for subprojects to actually consider as "source"
ext {
coverageSourceProjects = ["module-1"]
}
afterEvaluate {
task jacocoAggregateReport(type: JacocoReport) {
// Gather execution data from all subprojects
executionData fileTree(project.rootDir.absolutePath).include("**/build/jacoco/*.exec")
println("Coverage sources: " + coverageSourceProjects)
allprojects.each { project ->
if (project.name in coverageSourceProjects && project.hasProperty("sourceSets")) {
sourceSets project.sourceSets.main
}
}
reports {
xml.enabled true
html.enabled true
csv.enabled false
}
}
}
}
Since the InitScript executes before the buildSrc
directory is evaluated and the java plugin gets applied, non of the modules have any SourceSets defined. Therefore, this init script errors out:
A problem occurred configuring root project 'my-project'.
> Could not get unknown property 'sourceSets' for project ':module-1' of type org.gradle.api.Project.
How can I evaluate the Init Script after the buildSrc plugin has compiled?