Я изучал, как определить блок переменных в небольшом количестве подпроектов build.gradle.kts
, и прочитать эти блоки из задачи, определенной в root проекте 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 Проект 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
}
Я экспериментировал с project.ext
, project.extra
, gradle.ext
et c, но похоже, это если вы хотите прочитать свойство, заданное в rootProject, а не наоборот.
Gradle v.6.2.2