Gradle Shadow Plugin .jar not running on Docker container, no main manifest attribute

302 Views Asked by At

I built a fat jar using the Gradle Shadow Plugin like so:

tasks {
    "build" {
        dependsOn(shadowJar)
    }
    shadowJar {
        mergeServiceFiles {
            var path = "META-INF/"
        }
        manifest.inheritFrom(jar.get().manifest)
        manifest.attributes["Main-Class"] = "some.main.class.Main"
        manifest.attributes["Implementation-Version"] = version
    }
}

This works with no problem when I do gradle build and then java -jar fat_jar_name.jar, I have tested in MacOS, Windows and Ubuntu (WSL). The same command works exactly the same on all those platforms, even if the .jar was not locally built, but for some reason it is not working in Docker with eclipse-temurin.

I am trying to run a .jar file within Docker using:

FROM eclipse-temurin:17
ARG JAR_FILE=build/libs/*jar
COPY ${JAR_FILE} fat_jar_name-all.jar

ENTRYPOINT java -jar fat_jar_name.jar

I build the image using docker image build -t image_name ., and then I am trying to run it using docker run -d -p 8080:8080 image_name.

I get this error when running:

no main manifest attribute, in fat_jar_name-all.jar

I found that this issue is related to not having a META-INF\MANIFEST.MF file in the exported .jar. However, the fat_jar_name.jar does contain a manifest file with these contents:

Manifest-Version: 1.0
Main-Class: some.main.class.Main
Implementation-Version: 3.9.1-SNAPSHOT

Is there something I'm missing at the Docker, Gradle or Shadow Plugin level to make this work?

I found this resource for the Shadow Plugin about configuring the manifest, but it makes no mention of a main manifest attribute.

1

There are 1 best solutions below

0
buzoherbert On

I found that the COPY command I was using was broken. I used this one instead:

FROM eclipse-temurin:17
COPY build/libs/fat_jar_name-all.jar /
ENTRYPOINT java -jar fat_jar_name-all.jar