I have been looking into how to define a block of variables in a small number of subprojects build.gradle.kts
, and read these blocks from a task defined in the root project build.gradle.kts
.
SubProject1 build.gradle.kts
dependencies {
"implementation"("dependency.one:dep-one-api")
...
}
additionalProjectSpecificVars {
val additionalOptions = listOf<String>("option1", "option2", ...)
val additionalLocations = listOf<String>("$projectDir/location1/...", "$projectDir/location2/...")
}
Root Project build.gradle.kts
subprojects {
if (project.name.endsWith("-wsdl")) {
apply(plugin = "no.nils.wsdl2java")
dependencies {
...
}
tasks.withType<no.nils.wsdl2java.Wsdl2JavaTask> {
generatedWsdlDir = file("$projectDir/generatedsources")
wsdlDir = file("$projectDir/wsdl")
wsdlsToGenerate = gatherWsdlFiles()
}
}
}
fun Project.gatherWsdlFiles() : List<ArrayList<String>> {
// 2-D Array
var wsdlsToGenerateList = listOf<ArrayList<String>>()
// Gather all the files in the WSDL directory
val wsdlCollection = layout.files({
file("$projectDir/wsdl").listFiles()
})
// Filter out only the .wsdl files
val wsdlOnlyFiles: FileCollection = wsdlCollection.filter { file: File ->
file.name.endsWith(".wsdl")
}
// Iterate the files collection and add the cxf-parameters
wsdlOnlyFiles.forEach { wsdl: File ->
val wsdlArray = listOf<String>(
"-xjc-Xnamespace-prefix",
"-xjc-XhashCode",
"-xjc-Xequals",
"-xjc-XtoString",
wsdl.name)
wsdlsToGenerateList.plus(wsdlArray)
}
// Read and add the other options from the subprojects
// additionalProjectSpecificVars block here and add to
// wsdlsToGenerateList list
return wsdlsToGenerateList
}
I've experimented with project.ext
, project.extra
, gradle.ext
etc, but these seem to be if you want to read a property that has been set in the rootProject, rather than the reverse.
Gradle v.6.2.2