java.lang.NoClassDefFoundError: when trying to run jar

This is because your dependencies are not included into the end jar file.

Take a look on the examples here or here.

Or alternatively use ./gradlew clean build that should automatically pack the app correctly. Take a look on the official guide


  1. Define a task called fatJar in build.gradle:
jar {
    baseName = 'base-name'
    version = '0.1.0'
    manifest {
        attributes(
                'Main-Class': 'com.github:'
        )
    }
}

task fatJar(type: Jar) {
    manifest.from jar.manifest
//    classifier = 'all'
    from {
        configurations.runtime.collect { it.isDirectory() ? it : zipTree(it) }
    } {
        exclude "META-INF/*.SF"
        exclude "META-INF/*.DSA"
        exclude "META-INF/*.RSA"
    }
    with jar
}

artifacts {
    archives fatJar
}
  1. Run gradle fatJar or ./gradlew fatJar to generate a jar file with all dependencies, which can run independently but may be pretty large in size (that's why it's called a fat jar).