From d88e07dd2df6bac7bb58484cd740e86563b48fea Mon Sep 17 00:00:00 2001 From: mkuligowski Date: Sat, 2 Dec 2017 23:30:28 +0100 Subject: [PATCH 1/5] Add starting build.gradle file --- gradle/gradle-fat-jar/build.gradle | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 gradle/gradle-fat-jar/build.gradle diff --git a/gradle/gradle-fat-jar/build.gradle b/gradle/gradle-fat-jar/build.gradle new file mode 100644 index 0000000000..102bc96dfc --- /dev/null +++ b/gradle/gradle-fat-jar/build.gradle @@ -0,0 +1,10 @@ +apply plugin: 'java' + +repositories { + mavenCentral() +} + +dependencies{ + compile group: 'org.slf4j', name: 'slf4j-api', version: '1.7.25' + compile group: 'org.slf4j', name: 'slf4j-simple', version: '1.7.25' +} \ No newline at end of file From 3f8fb8dd78dff603b28f73ba8833b84425894b35 Mon Sep 17 00:00:00 2001 From: mkuligowski Date: Sat, 2 Dec 2017 23:30:55 +0100 Subject: [PATCH 2/5] Add main class --- .../java/com/baeldung/fatjar/Application.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 gradle/gradle-fat-jar/src/main/java/com/baeldung/fatjar/Application.java diff --git a/gradle/gradle-fat-jar/src/main/java/com/baeldung/fatjar/Application.java b/gradle/gradle-fat-jar/src/main/java/com/baeldung/fatjar/Application.java new file mode 100644 index 0000000000..470d89c332 --- /dev/null +++ b/gradle/gradle-fat-jar/src/main/java/com/baeldung/fatjar/Application.java @@ -0,0 +1,16 @@ +package com.baeldung.fatjar; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +public class Application { + + static final Logger logger = LoggerFactory.getLogger(Application.class); + + public static void main(String[] args) { + + logger.info("Hello at Baeldung!"); + } + +} \ No newline at end of file From b152de4851aaea4cee444191bafa893a29741e89 Mon Sep 17 00:00:00 2001 From: mkuligowski Date: Sun, 3 Dec 2017 10:56:52 +0100 Subject: [PATCH 3/5] Modify jar task from java plugin in order to produce fat-jar --- gradle/gradle-fat-jar/build.gradle | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/gradle/gradle-fat-jar/build.gradle b/gradle/gradle-fat-jar/build.gradle index 102bc96dfc..334583d486 100644 --- a/gradle/gradle-fat-jar/build.gradle +++ b/gradle/gradle-fat-jar/build.gradle @@ -4,6 +4,16 @@ repositories { mavenCentral() } +jar { + manifest { + attributes "Main-Class": "com.baeldung.fatjar.Application" + } + + from { + configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } + } +} + dependencies{ compile group: 'org.slf4j', name: 'slf4j-api', version: '1.7.25' compile group: 'org.slf4j', name: 'slf4j-simple', version: '1.7.25' From 867e8ef3bec6dee4c4f77e591f64fbc3cf8b77ad Mon Sep 17 00:00:00 2001 From: mkuligowski Date: Sun, 3 Dec 2017 11:23:53 +0100 Subject: [PATCH 4/5] Add custom task which produces fat jar --- gradle/gradle-fat-jar/build.gradle | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/gradle/gradle-fat-jar/build.gradle b/gradle/gradle-fat-jar/build.gradle index 334583d486..23d66943cb 100644 --- a/gradle/gradle-fat-jar/build.gradle +++ b/gradle/gradle-fat-jar/build.gradle @@ -14,6 +14,17 @@ jar { } } + +task customFatJar(type: Jar) { + manifest { + attributes 'Main-Class': 'com.baeldung.fatjar.Application' + } + baseName = 'all-in-one-jar' + from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } } + with jar +} + + dependencies{ compile group: 'org.slf4j', name: 'slf4j-api', version: '1.7.25' compile group: 'org.slf4j', name: 'slf4j-simple', version: '1.7.25' From e75a143e9f386ec7f5916b7cfe7506d23adeafca Mon Sep 17 00:00:00 2001 From: mkuligowski Date: Sun, 3 Dec 2017 11:26:27 +0100 Subject: [PATCH 5/5] Add shadow plugin --- gradle/gradle-fat-jar/build.gradle | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/gradle/gradle-fat-jar/build.gradle b/gradle/gradle-fat-jar/build.gradle index 23d66943cb..6afad80652 100644 --- a/gradle/gradle-fat-jar/build.gradle +++ b/gradle/gradle-fat-jar/build.gradle @@ -1,4 +1,14 @@ +buildscript { + repositories { + jcenter() + } + dependencies { + classpath 'com.github.jengelman.gradle.plugins:shadow:2.0.1' + } +} + apply plugin: 'java' +apply plugin: 'com.github.johnrengelman.shadow' repositories { mavenCentral()