diff --git a/build.gradle.kts b/build.gradle.kts index 6b583e2b2..b297bc9de 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -9,6 +9,17 @@ plugins { id("com.github.gmazzo.buildconfig") version "3.0.3" apply false } +buildscript { + repositories { + mavenCentral() + } + dependencies { + classpath("com.guardsquare:proguard-gradle:7.2.1") { + exclude("com.android.tools.build") + } + } +} + allprojects { group = "suwayomi" @@ -112,4 +123,5 @@ configure(projects) { // dependency both in AndroidCompat and server, version locked by javalin implementation("com.fasterxml.jackson.core:jackson-annotations:2.12.4") } -} \ No newline at end of file +} + diff --git a/server/build.gradle.kts b/server/build.gradle.kts index 8efc89de9..9c7a786eb 100644 --- a/server/build.gradle.kts +++ b/server/build.gradle.kts @@ -1,4 +1,5 @@ import de.undercouch.gradle.tasks.download.Download +import proguard.gradle.ProGuardTask import java.time.Instant plugins { @@ -175,4 +176,25 @@ tasks { ) } } + + register("optimizeShadowJar") { + group = "shadow" + val shadowJar = getByName("shadowJar") + dependsOn(shadowJar) + val shadowJars = shadowJar.outputs.files.onEach { println(it.absolutePath) } + injars(shadowJars) + outjars( + shadowJars.map { file -> + File(file.parentFile, "min/" + file.name) + } + ) + val javaHome = System.getProperty("java.home") + if (JavaVersion.current().isJava9Compatible) { + libraryjars("$javaHome/jmods") + } else { + libraryjars("$javaHome/lib/rt.jar") + //libraryjars("$javaHome/lib/jce.jar") + } + configuration("proguard-rules.pro") + } } diff --git a/server/proguard-rules.pro b/server/proguard-rules.pro new file mode 100644 index 000000000..4c9cd8c3b --- /dev/null +++ b/server/proguard-rules.pro @@ -0,0 +1,138 @@ +-dontobfuscate +-keepattributes Signature,LineNumberTable + +-keep,allowoptimization class eu.kanade.tachiyomi.** { public protected *; } +-keep,allowoptimization class suwayomi.tachidesk.** { public protected *; } +-keep class suwayomi.tachidesk.manga.model.dataclass.* { *; } +-keep class suwayomi.tachidesk.MainKt { + public static void main(java.lang.String[]); +} +-keepdirectories suwayomi/tachidesk/** +-keepdirectories META-INF/** + + +# java.lang.ClassCastException: class javax.servlet.SessionTrackingMode not an enum +-keepclassmembers class * extends java.lang.Enum { + ; + public static **[] values(); + public static ** valueOf(java.lang.String); +} + +# Jackston +#-keep class kotlin.Metadata { *; } +#-keep class kotlin.reflect.** { *; } + + +# Kotlin Serialization +-keepattributes *Annotation*, InnerClasses +-dontnote kotlinx.serialization.AnnotationsKt # core serialization annotations + +# kotlinx-serialization-json specific. Add this if you have java.lang.NoClassDefFoundError kotlinx.serialization.json.JsonObjectSerializer +-keepclassmembers class kotlinx.serialization.json.** { + *** Companion; +} +-keepclasseswithmembers class kotlinx.serialization.json.** { + kotlinx.serialization.KSerializer serializer(...); +} + +-keep,includedescriptorclasses class eu.kanade.tachiyomi.**$$serializer { *; } +-keepclassmembers class eu.kanade.tachiyomi.** { + *** Companion; +} +-keepclasseswithmembers class eu.kanade.tachiyomi.** { + kotlinx.serialization.KSerializer serializer(...); +} + +-keep,includedescriptorclasses class suwayomi.tachidesk.**$$serializer { *; } +-keepclassmembers class suwayomi.tachidesk.** { + *** Companion; +} +-keepclasseswithmembers class suwayomi.tachidesk.** { + kotlinx.serialization.KSerializer serializer(...); +} + +# Keep extension's common dependencies +-keep,allowoptimization class eu.kanade.tachiyomi.** { public protected *; } +-keep,allowoptimization class androidx.preference.** { *; } +-keep,allowoptimization class kotlin.** { public protected *; } +-keep,allowoptimization class kotlinx.coroutines.** { public protected *; } +-keep,allowoptimization class okhttp3.** { public protected *; } +-keep,allowoptimization class okio.** { public protected *; } +-keep,allowoptimization class rx.** { public protected *; } +-keep,allowoptimization class org.jsoup.** { public protected *; } +-keep,allowoptimization class com.google.gson.** { public protected *; } +-keep,allowoptimization class com.github.salomonbrys.kotson.** { public protected *; } +-keep,allowoptimization class com.squareup.duktape.** { public protected *; } +-keep,allowoptimization class app.cash.quickjs.** { public protected *; } +-keep,allowoptimization class uy.kohesive.injekt.** { public protected *; } +-keep,allowoptimization class kotlinx.serialization.** { public protected *; } + +# Coroutines +-dontwarn kotlinx.coroutines.** + +# OKHTTP +-dontwarn org.codehaus.mojo.animal_sniffer.* +-dontwarn okhttp3.internal.platform.** + +# Exposted +-keep class org.jetbrains.exposed.** { *; } +-keep class de.neonew.exposed.migrations.** { *; } + +# H2 +-keep class org.h2.Driver { *; } + +# Javalin +-keep class org.eclipse.jetty.** { *; } +-dontwarn io.javalin.http.LeveledBrotliStream +-dontwarn io.javalin.plugin.metrics.** +-dontwarn io.javalin.plugin.rendering.** +-dontwarn com.nixxcode.jvmbrotli.common.BrotliLoader +-dontwarn com.nixxcode.jvmbrotli.enc.BrotliOutputStream + +# Xml +-keep class org.apache.xerces.** { *; } +-dontwarn javax.xml.** +-dontwarn com.sun.xml.** +-dontwarn com.sun.org.apache.** +-dontwarn jdk.xml.internal.ErrorHandlerProxy +-dontwarn com.sun.beans.decoder.DocumentHandler +-dontwarn org.apache.xerces.** + +# org.json +-dontwarn org.json.XMLTokener +-dontwarn org.json.JSONWriter + +# Android +-dontwarn com.android.** +-dontwarn android.** +-dontwarn androidx.annotation.* + +# Logback +-keep class ch.qos.logback.** { *; } +-dontwarn ch.qos.logback.** +-dontwarn org.apache.commons.logging.** +-dontwarn org.slf4j.MDC +-dontwarn org.slf4j.MarkerFactory + +# Dorkbox +-keep class dorkbox.systemTray.ui.** { + public (...); +} +-keep class dorkbox.jna.** { *; } +-dontwarn dorkbox.** + +# Java +-dontwarn javax.imageio.** +-dontwarn javax.swing.** +-dontwarn java.util.prefs.** + +# Joda time +-dontwarn org.joda.convert.* + +# Other +-keep class com.sun.jna.** { *; } +-dontwarn com.sun.rowset.** +-dontwarn com.reprezen.jsonoverlay.gen.** +-dontwarn org.h2.** +-dontwarn org.eclipse.jetty.** +-dontwarn org.antlr.runtime.tree.DOTTreeGenerator