Skip to main content

Run Springboot fatjar with Palantir Docker Gradle plugin

When creating Docker images for a Springboot project using the Palantir Docker plugin I found no easy way to pick up the fat jar from the bootRepackage task.

One way around this is to set each the jar and the bootRepackage tasks as dependencies. The jar tasks provides the output (which the Docker plugin will pick up) and the bootRepackage actually generates the proper file (with the same name).

docker {
    name "ofnir/app:${project.version}"
    dependsOn tasks.jar, tasks.bootRepackage

Provide a fixed name for the jar, so it's easier to refer from the Dockerfile:

jar {
    baseName = 'ofnir-app'
    version = null
    manifest {
        attributes 'Main-Class': mainClassName

This will generate ofnir-app.jar.

Then a Dockerfile can be as simple as:

FROM java:8
COPY onfir-app.jar /usr/local/
CMD ["java", "-jar", "/usr/local/onfir-app.jar"]