Skip to content
Latchkey

gradle jar: Usage & Common CI Errors

Build the project JAR - but know when you actually want bootJar.

jar is the task added by the Java plugin that assembles a JAR archive containing the main source set’s compiled classes and resources. It produces a plain library jar in build/libs.

What it does

jar packages build/classes and resources into a .jar. A plain jar contains only your classes - not dependencies - so it is not self-runnable. For an executable fat jar with dependencies, the Spring Boot plugin’s bootJar (or the shadow plugin’s shadowJar) is required.

Common usage

Terminal
./gradlew jar
./gradlew bootJar       # Spring Boot executable fat jar
./gradlew shadowJar     # shadow plugin fat jar

Common error in CI (and the fix)

Symptom: running the produced jar fails with "no main manifest attribute, in app.jar" or a NoClassDefFoundError for a dependency. Cause: a plain jar task output has no Main-Class manifest and no bundled dependencies. Fix: build the executable artifact instead - ./gradlew bootJar for Spring Boot apps, or a shadow/uber jar - and deploy that jar, not the plain library jar.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →