The Gradle plugin's current support for repackaging a jar to create a fat executable jar is, pretty much, a direct conversion of the equivalent functionality in the Maven plugin. As such, it could be a better Gradle citizen than it is at the moment.
RepackageTask
figures out what it should do, rather than being configured by the plugin. This makes the task hard to reuse. The plugin should provide a default, pre-configured task for producing a fat jar.RepackageTask
doesn't declare its inputs and outputs in a conventional manner. This means that Gradle's up-to-date checking doesn't work as it should. For example, changing the embedded launch script properties won't cause the fat jar to be rebuilt. The task should be updated to fully declare all of its inputs and outputs by using the relevant @Input
and @Output…
annotations.As part of addressing all of the above, I think we should consider not actually repackaging an existing jar or war file. Instead, we should have BootJar
and BootWar
tasks that are subclasses of Gradle's Jar
and War
tasks respectively. They will use the appropriate source set's output as (part of) their input. This should make it significantly easier to configure task dependencies. It will also make it easier to address 7 and 8 as it's trivial to create a PublishArtifact
from an AbstractArchiveTask
subclass. This is the approach taken by the shadow plugin and its ShadowJar.
Might I suggest that it would be nice to be able to get the path to the repackaged file somehow? The use case: I generate Cloud Foundry's manifest.yml to include the path attribute to point to the generated file. Right now I rely on the fact that the name is the same as the jar task's output as long I don't use any classifier. I would like to use one, though, as the repackage task wouldn't then force gradle to re-run jar again and again.
I guess if you subclass the default JarTask, this feature will be available for free. If not, would you consider exposing the generated file path somehow?
Yes, please become a nicer gradle citizen (just got bitten by the fact that bootRepackage does not properly expose the output filename...)
👍 for @otrosien 's use case (getting the jar file for CF), although some of this could probably be handled by cf accepting patterns.
Most helpful comment
Yes, please become a nicer gradle citizen (just got bitten by the fact that bootRepackage does not properly expose the output filename...)