The build-image Mojo doesn't attempt to re-use an existing JAR file that it has already built. This is a small change that just checks if it already exists and re-uses it.
A side effect is that other plugins can modify the JAR file (e.g. to optimize the reflection usage for a native-image build) and those changes are visible in the container image.
Possibly something similar can be done in the Gradle plugin?
Comment From: wilkinsona
Possibly something similar can be done in the Gradle plugin?
By default, the Gradle plugin already uses the output of the BootJar
task when creating the image. It should be possible to use a dependency substitution to swap in the optimised Tomcat dependency.
Comment From: philwebb
Unfortunately, I'm not convinced that this change will always work. There's some logic in ImagePackager.packageImage
that ensures the non-repackaged source is always used. With the suggested change, we lose control over what actually gets uploaded and if the user hasn't created a fat jar, the OCI image will break. We also faced problems with Gradle when uploading packaged jars that include a launch script in the front.
I think if other optimizations are needed, we should look at some kind of dedicated API hook.