How to create fat jar with gradle
What is fat jar
When we create jar file, jar file includes only we tried to compile on our project.
Fat jar includes all dependencies of this project.
Use library
fatjar-plugin supports fat jar creation. 🙂
Add description to build.gradle
buildscript { repositories { jcenter() } dependencies { classpath("org.springframework.boot:spring-boot-gradle-plugin:1.4.0.RELEASE") classpath("eu.appsatori:gradle-fatjar-plugin:0.3") } } apply plugin: "java" apply plugin: "spring-boot" apply plugin: "idea" apply plugin: "eu.appsatori.fatjar" idea { module { inheritOutputDirs = false outputDir = file("$buildDir/classes/main/") } } repositories { mavenCentral() } fatJar { baseName = 'SpringBatchSample2Fat' manifest { attributes 'Main-Class' : 'yourownmainclass' } } dependencies { compile('org.springframework.boot:spring-boot-starter-batch') compile('mysql:mysql-connector-java:5.1.40') testCompile("org.springframework.boot:spring-boot-starter-test") }
The important parts are
dependencies { classpath("org.springframework.boot:spring-boot-gradle-plugin:1.4.0.RELEASE") classpath("eu.appsatori:gradle-fatjar-plugin:0.3") }
Add dependency of fat jar library
fatJar { baseName = 'SpringBatchSampleFat' manifest { attributes 'Main-Class' : 'yourownmainclass' } }
This is fat jar task for gradle
baseName is jar file name.
manifest is same as jar file.
This fat jar includes all classes you need(including Spring boot dependencies in this case).
Create fat jar
On your project root
gradle fatJar
Make jar file under build/libs