diff --git a/build.gradle b/build.gradle index 4ebb865..2ef472e 100644 --- a/build.gradle +++ b/build.gradle @@ -1,3 +1,12 @@ +buildscript { + repositories { + mavenCentral() + } + dependencies { + classpath 'net.sf.proguard:proguard-gradle:6.2.2' + } +} + plugins { id 'java' id 'application' @@ -7,6 +16,32 @@ plugins { group 'com.annimon' version '1.0-SNAPSHOT' mainClassName = 'com.annimon.imagetagger.Main' +def archiveName = "${rootProject.name}" +def shadowFileName = "$archiveName-all.jar" +def proguardFileName = "$archiveName-proguard.jar" + +shadowJar { + mergeServiceFiles() + archiveFileName = shadowFileName +} + +task proguard(dependsOn: shadowJar, type: proguard.gradle.ProGuardTask) { + configuration "$rootProject.projectDir/proguard.pro" + injars "${file(jar.destinationDirectory)}/$shadowFileName" + outjars "${file(jar.destinationDirectory)}/$proguardFileName" + + // Automatically handle the Java version of this build. + if (System.getProperty('java.version').startsWith('1.')) { + // Before Java 9, the runtime classes were packaged in a single jar file. + libraryjars "${System.getProperty('java.home')}/lib/rt.jar" + } else { + // As of Java 9, the runtime classes are packaged in modular jmod files. + def jmods = files { file("${System.getProperty('java.home')}/jmods").listFiles() } + jmods.each { + libraryjars it, jarfilter: '!**.jar', filter: '!module-info.class' + } + } +} repositories { mavenCentral() diff --git a/proguard.pro b/proguard.pro new file mode 100644 index 0000000..a5bf165 --- /dev/null +++ b/proguard.pro @@ -0,0 +1,29 @@ +-keepattributes Signature,InnerClasses +-keepattributes *Annotation* + +-keep class com.annimon.imagetagger.beans.** { *; } +-keep class com.github.benmanes.caffeine.cache.** { *; } + +# Jackson 2 +-keep class com.fasterxml.jackson.databind.ObjectMapper { + public protected ; +} +-dontwarn com.fasterxml.jackson.databind.** +-keepclassmembers class * { + @com.fasterxml.jackson.annotation.* *; +} + +# Java +-keepclasseswithmembers public class * { + public static void main(java.lang.String[]); +} +-keepclassmembers enum * { + public static **[] values(); + public static ** valueOf(java.lang.String); +} +-keep class * extends javax.swing.plaf.ComponentUI { + public static javax.swing.plaf.ComponentUI createUI(javax.swing.JComponent); +} +-keepclasseswithmembers,includedescriptorclasses,allowshrinking class * { + native ; +}