Last active
March 9, 2024 05:25
-
-
Save adierebel/bfd4276b35596d937c763b1e05a7c9d2 to your computer and use it in GitHub Desktop.
Proguard + Shadow JAR for non Android Project (Java 11 Swing)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile | |
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar | |
import proguard.gradle.ProGuardTask | |
plugins { | |
id("application") | |
id("org.jetbrains.kotlin.jvm") version "1.6.0" | |
id("com.github.johnrengelman.shadow") version "7.1.0" | |
} | |
repositories { | |
mavenCentral() | |
gradlePluginPortal() | |
maven { setUrl("https://jitpack.io") } | |
} | |
dependencies { | |
implementation(kotlin("stdlib-jdk8")) | |
implementation("com.google.code.gson:gson:2.8.9") | |
testImplementation("org.junit.jupiter:junit-jupiter:5.7.2") | |
} | |
buildscript { | |
repositories { | |
mavenCentral() | |
} | |
dependencies { | |
classpath("com.guardsquare:proguard-gradle:7.1.1") { | |
exclude("com.android.tools.build") | |
} | |
} | |
} | |
application { | |
mainClass.set("com.adierebel.MainKt") | |
sourceSets["main"].resources { | |
srcDir("src/main/res") | |
} | |
sourceSets["main"].java { | |
srcDir("src/main/java") | |
} | |
} | |
tasks.jar { enabled = false } | |
artifacts.archives(tasks.shadowJar) | |
tasks.withType<KotlinCompile> { | |
kotlinOptions { | |
jvmTarget = "1.8" | |
} | |
} | |
tasks.withType<ShadowJar> { | |
archiveFileName.set("app.jar") | |
exclude("DebugProbesKt.bin") | |
exclude("META-INF/**") | |
} | |
tasks.register<ProGuardTask>("proguardJar") { | |
outputs.upToDateWhen { false } | |
dependsOn("clean") | |
dependsOn("shadowJar") | |
configuration("proguard-rules.pro") | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-injars build/libs/app.jar | |
-outjars build/libs/app-min.jar | |
-libraryjars <java.home>/jmods/java.base.jmod(!**.jar;!module-info.class) | |
-libraryjars <java.home>/jmods/java.compiler.jmod(!**.jar;!module-info.class) | |
-libraryjars <java.home>/jmods/java.datatransfer.jmod(!**.jar;!module-info.class) | |
-libraryjars <java.home>/jmods/java.desktop.jmod(!**.jar;!module-info.class) | |
-libraryjars <java.home>/jmods/java.instrument.jmod(!**.jar;!module-info.class) | |
-libraryjars <java.home>/jmods/java.logging.jmod(!**.jar;!module-info.class) | |
-libraryjars <java.home>/jmods/java.management.jmod(!**.jar;!module-info.class) | |
-libraryjars <java.home>/jmods/java.management.rmi.jmod(!**.jar;!module-info.class) | |
-libraryjars <java.home>/jmods/java.naming.jmod(!**.jar;!module-info.class) | |
-libraryjars <java.home>/jmods/java.net.http.jmod(!**.jar;!module-info.class) | |
-libraryjars <java.home>/jmods/java.prefs.jmod(!**.jar;!module-info.class) | |
-libraryjars <java.home>/jmods/java.rmi.jmod(!**.jar;!module-info.class) | |
-libraryjars <java.home>/jmods/java.scripting.jmod(!**.jar;!module-info.class) | |
-libraryjars <java.home>/jmods/java.se.jmod(!**.jar;!module-info.class) | |
-libraryjars <java.home>/jmods/java.security.jgss.jmod(!**.jar;!module-info.class) | |
-libraryjars <java.home>/jmods/java.security.sasl.jmod(!**.jar;!module-info.class) | |
-libraryjars <java.home>/jmods/java.smartcardio.jmod(!**.jar;!module-info.class) | |
-libraryjars <java.home>/jmods/java.sql.jmod(!**.jar;!module-info.class) | |
-libraryjars <java.home>/jmods/java.sql.rowset.jmod(!**.jar;!module-info.class) | |
-libraryjars <java.home>/jmods/java.transaction.xa.jmod(!**.jar;!module-info.class) | |
-libraryjars <java.home>/jmods/java.xml.crypto.jmod(!**.jar;!module-info.class) | |
-libraryjars <java.home>/jmods/java.xml.jmod(!**.jar;!module-info.class) | |
-dontoptimize | |
-dontshrink | |
-keep class !com.adierebel.**, !com.adierebel.** { *; } | |
-keepclasseswithmembers public class com.javafx.main.Main, org.eclipse.jdt.internal.jarinjarloader.*, com.adierebel.MainKt { | |
public static void main(java.lang.String[]); | |
} | |
-dontwarn okio.** | |
-dontwarn okhttp3.** | |
-dontwarn retrofit2.** | |
-dontwarn org.apache.** | |
-dontwarn com.sun.** | |
-dontwarn com.j256.ormlite.** | |
-dontwarn com.google.protobuf.** | |
-dontwarn com.google.common.** | |
-dontwarn com.mysql.** | |
-dontwarn java.util.** | |
-dontwarn javax.imageio.** | |
-dontwarn javax.swing.plaf.** | |
-dontwarn javax.xml.** | |
-dontwarn java.sql.** | |
-ignorewarnings | |
# GSON | |
-keepattributes Signature | |
-keepattributes Signature | |
-keep class * extends com.google.gson.TypeAdapter | |
-keep class * implements com.google.gson.TypeAdapterFactory | |
-keep class * implements com.google.gson.JsonSerializer | |
-keep class * implements com.google.gson.JsonDeserializer | |
-keepclassmembers,allowobfuscation class * { | |
@com.google.gson.annotations.SerializedName <fields>; | |
} | |
-keep,allowobfuscation,allowshrinking class com.google.gson.reflect.TypeToken | |
-keep,allowobfuscation,allowshrinking class * extends com.google.gson.reflect.TypeToken |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment