Skip to content

Instantly share code, notes, and snippets.

@kimhanjoon
Created December 3, 2017 05:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kimhanjoon/7423bcc8e062832fbb25527c764f3e2a to your computer and use it in GitHub Desktop.
Save kimhanjoon/7423bcc8e062832fbb25527c764f3e2a to your computer and use it in GitHub Desktop.
spring-boot-gradle-proguard-excutable-jar
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.5.8.RELEASE")
classpath("net.sf.proguard:proguard-gradle:5.3.3")
}
}
apply plugin: 'java'
apply plugin: 'org.springframework.boot'
sourceCompatibility = 1.8
targetCompatibility = 1.8
compileJava.options.encoding = 'UTF-8'
compileTestJava.options.encoding = 'UTF-8'
springBoot {
executable = true
}
def proguardJarPath = jar.archivePath.absolutePath.replace(".jar", "-proguard.jar")
task proguard(type: proguard.gradle.ProGuardTask, dependsOn: jar) {
configuration "proguard.conf"
injars jar.archivePath.absolutePath
outjars proguardJarPath
libraryjars "${System.getProperty('java.home')}/lib/rt.jar"
libraryjars project.configurations.compile
}
task proguardJar(type: Jar, overwrite: true, dependsOn: proguard) {
from zipTree(proguardJarPath)
}
bootRepackage {
withJarTask = proguardJar
}
repositories {
mavenCentral()
}
dependencies {
compile "org.springframework.boot:spring-boot-starter-web"
}
@mikeshi80
Copy link

Great, but it does not work in Spring Boot 2.0 since Gradle plugin API has changed a lot.

@ricmf
Copy link

ricmf commented Sep 4, 2018

@mikeshi80 did you find a way to get it working with spring boot 2.0?

@glebsts
Copy link

glebsts commented Oct 18, 2018

@ricmf @mikeshi80 any hope? :)

@wolfe
Copy link

wolfe commented Mar 11, 2020

Works with Spring Boot 1.5.22 but I had to delete the "overwrite: true" argument to proguardJar

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment