Java Gradle Build: NoClassDefFoundError Java Gradle Build: NoClassDefFoundError heroku heroku

Java Gradle Build: NoClassDefFoundError


To run your app without any NoClassDefFoundError, you should have your dependencies in the runtime class path. Creating a fat jar is the simplest solution. Change your jar section like below;

jar {    manifest {       attributes(          'Class-Path': configurations.compile.files.collect {"$it.name"}.join(' '),          'Main-Class': 'products.ProductAPI')}    from {        configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }    }}

run gradle build command and jar with dependencies will be created.Other way is to add jars to runtime class path are; with java -cp flag. (Also If your application has already a classpath folder configured, copying dependencies in this folder will add them to the classpath)