There's a lot of other related questions on this, but I haven't been able to get anything working here.
I'm using shadowjar in a subset of my subprojects to product a far jar. One of the subprojects produces two jars (different main class). I'm trying to eliminate the boilerplate in each subproject.
I've tried a few things, but using "extra" seems like the most canonical approach I've tried so far. But, it doesn't work.
In the root, I have:
subprojects {
afterEvaluate {
val jarFiles by project.extra(listOf<String>())
val mainClasses by project.extra(listOf<String>())
if (jarFiles != null && jarFiles.isNotEmpty()) {
jarFiles.forEachIndexed { idx, jarName ->
tasks.create<com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar>(jarName) {
isZip64 = true
archiveBaseName.set(jarName)
mergeServiceFiles()
manifest {
attributes(mapOf("Main-Class" to mainClasses!![idx]))
}
minimize()
}
tasks.build {
dependsOn(jarName)
}
}
}
}
And then in the subprojects I've tried:
extra["jarFiles"] = listOf("myproject")
extra["mainClasses"] = listOf("com.foo.Application")
or
val jarFiles by extra(listOf("internal", "external"))
val mainClasses by extra(listOf("com.fooInternalApplication", "com.foo.ExternalApplication"))
However, it's not getting fired. Am I close or should I take an entirely different approach?