Your implementation is less than ideal. Particularly, by explicitly executing task actions you effectively circumvent a lot of Gradle logic to accomplish things like incremental task support. Instead, what I would suggest is defining the task that creates your final jar, assign that artifact to a custom configuration, then have the other projects in your multi-project build, depend on that configuration.
I tried creating a configuration, but didn’t like it because it exposes details about what happens inside a subproject. My next step in that direction was to have specific configuration ‘finalJar’ for each Java plugin. I guess I have to revisit that approach unless it’s safe to do this:
jar.ext.finalizeIntermediate = { finalizeAction ->
jar {
def oldClassifier
doFirst {
// Temporarily change properties to produce 'intermediate' file,
// set 'jar.intermediateArchivePath'
oldClassifier = jar.classifier
jar.classifier = (oldClassifier ?: "") + "(INTERMEDIATE)"
jar.ext.intermediateArchivePath = jar.archivePath
}
doLast {
// Restore properties
jar.classifier = oldClassifier
// Run 'finalizeAction' which is expected to take 'jar.intermediateArchivePath'
// and produce 'jar.archivePath' (by obfuscating, applying jarjar, etc.)
finalizeAction()
}
}
}
I.e. instead of manually invoking Jar actions I do my thing before and after standard Jar tasks. Will that interfere with incremental feature?