This message was deleted.
# gradle
s
This message was deleted.
a
Copy code
tasks.register<proguard.gradle.ProGuardTask>("proguard") {
    configuration(file("<http://proguard.pro|proguard.pro>"))
    injars(tasks.shadowJar.flatMap { it.archiveFile })
    outjars(
        layout.buildDirectory.file("libs/${tasks.shadowJar.get().archiveFile.get().asFile.nameWithoutExtension}-minified.jar"),
    )

    // 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.
//        libraryjars("${System.getProperty("java.home")}/jmods/java.base.jmod", jarfilter: "!**.jar", filter: "!module-info.class")
        libraryjars("${System.getProperty("java.home")}/jmods/.....")
    }

    // This will include the Kotlin library jars
    libraryjars(sourceSets.main.get().compileClasspath)

    verbose()
}
Well, I already did and didn't find the solution, Kotlin related software like Compose Desktop or Android already use Proguard by default, so maybe there are developers who are already familiar with it, most solutions are related to Android
But you are right, it's not directly related to Gradle as mentioned in the question, I will try to find another resource and move the question
> There is no template solution if you build your own app. Well, the issue happen even when using
suspend
keyword, so it's not related or specific to my application
I have been searching for days and still no solution.
That's might be another subject, the point is that the provided example in Proguard doesn't showcase using it with Kotlin, once you start using any import like
Random
from
kotlin
you will get an error. using java imports doesn't have such issues because it's already in the JRE
Yet there are workarounds and solutions to using it with Kotlin, I already filed an issue to Proguard, it's not Jetbrains product The
application-kotlin
from proguard example is a little bit outdated.
Thank you for your help, I'm removing the issue and moving it to somewhere related to Proguard, the problem is they don't have discussions in Github and I would rather not mixing the issues (bugs and feature requests) with the questions in any project, I already used Proguard community and I got no response.
Not sure what does
endeavors
mean, Good luck to you too.
Found the solution
Copy code
val javaHome = System.getProperty("java.home")
    if (System.getProperty("java.version").startsWith("1.")) {
        // Before Java 9, runtime classes are packaged in a single JAR file.
        libraryjars("$javaHome/lib/rt.jar")
    } else {
        // Starting from Java 9, runtime classes are packaged in modular JMOD files.
        libraryjars(
            mapOf("jarfilter" to "!**.jar", "filter" to "!module-info.class"),
            "$javaHome/jmods/java.base.jmod",
        )
    }

 printmapping(destinationDirectory.file("$originalJarNameWithoutExtension.map"))

    // TODO: Workaround to fix `Please correct the above warnings first`
    ignorewarnings()
    dontobfuscate()
    dontoptimize()
    dontwarn()

    configuration(file("<http://proguard.pro|proguard.pro>"))
The rules depends on your application and mainly libraries, for my use-case:
Copy code
# Proguard Kotlin Example <https://github.com/Guardsquare/proguard/blob/master/examples/application-kotlin/proguard.pro>

-keepattributes *Annotation*

-keep class kotlin.Metadata { *; }

# Entry point to the app.
-keep class MainKt { *; }

# Kotlinx Serialization <https://github.com/Kotlin/kotlinx.serialization/blob/master/rules/common.pro>

# Keep `Companion` object fields of serializable classes.
# This avoids serializer lookup through `getDeclaredClasses` as done for named companion objects.
-if @kotlinx.serialization.Serializable class **
-keepclassmembers class <1> {
    static <1>$Companion Companion;
}

# Keep `serializer()` on companion objects (both default and named) of serializable classes.
-if @kotlinx.serialization.Serializable class ** {
    static **$* *;
}
-keepclassmembers class <2>$<3> {
    kotlinx.serialization.KSerializer serializer(...);
}

# Keep `INSTANCE.serializer()` of serializable objects.
-if @kotlinx.serialization.Serializable class ** {
    public static ** INSTANCE;
}
-keepclassmembers class <1> {
    public static <1> INSTANCE;
    kotlinx.serialization.KSerializer serializer(...);
}

# @Serializable and @Polymorphic are used at runtime for polymorphic serialization.
-keepattributes RuntimeVisibleAnnotations,AnnotationDefault

# Don't print notes about potential mistakes or omissions in the configuration for kotlinx-serialization classes
# See also <https://github.com/Kotlin/kotlinx.serialization/issues/1900>
-dontnote kotlinx.serialization.**

# Serialization core uses `java.lang.ClassValue` for caching inside these specified classes.
# If there is no `java.lang.ClassValue` (for example, in Android), then R8/ProGuard will print a warning.
# However, since in this case they will not be used, we can disable these warnings
-dontwarn kotlinx.serialization.internal.ClassValueReferences

# Kotlinx Coroutines <https://github.com/Kotlin/kotlinx.coroutines/blob/master/kotlinx-coroutines-core/jvm/resources/META-INF/proguard/coroutines.pro>

# ServiceLoader support
-keepnames class kotlinx.coroutines.internal.MainDispatcherFactory {}
-keepnames class kotlinx.coroutines.CoroutineExceptionHandler {}

# Most of volatile fields are updated with AFU and should not be mangled
-keepclassmembers class kotlinx.coroutines.** {
    volatile <fields>;
}

# Same story for the standard library's SafeContinuation that also uses AtomicReferenceFieldUpdater
-keepclassmembers class kotlin.coroutines.SafeContinuation {
    volatile <fields>;
}

# These classes are only required by kotlinx.coroutines.debug.AgentPremain, which is only loaded when
# kotlinx-coroutines-core is used as a Java agent, so these are not needed in contexts where ProGuard is used.
-dontwarn java.lang.instrument.ClassFileTransformer
-dontwarn sun.misc.SignalHandler
-dontwarn java.lang.instrument.Instrumentation
-dontwarn sun.misc.Signal

# Only used in `kotlinx.coroutines.internal.ExceptionsConstructor`.
# The case when it is not available is hidden in a `try`-`catch`, as well as a check for Android.
-dontwarn java.lang.ClassValue

# An annotation used for build tooling, won't be directly accessed.
-dontwarn org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement

# OkHttp <https://square.github.io/okhttp/features/r8_proguard/>

# JSR 305 annotations are for embedding nullability information.
-dontwarn javax.annotation.**

# A resource is loaded with a relative path so the package of this class must be preserved.
-keeppackagenames okhttp3.internal.publicsuffix.*
-adaptresourcefilenames okhttp3/internal/publicsuffix/PublicSuffixDatabase.gz

# Animal Sniffer compileOnly dependency to ensure APIs are compatible with older versions of Java.
-dontwarn org.codehaus.mojo.animal_sniffer.*

# OkHttp platform used only on JVM and when Conscrypt and other security providers are available.
-dontwarn okhttp3.internal.platform.**
-dontwarn org.conscrypt.**
-dontwarn org.bouncycastle.**
-dontwarn org.openjsse.**

# Okio (missing)

# FlatLaf

# Exclude the entire FlatLaf dependency from minimization to fix `no ComponentUI class for: javax.swing.<component>`
# Due to reflections, more details: <https://github.com/JFormDesigner/FlatLaf/issues/648#issuecomment-1441547550>
-keep class com.formdev.flatlaf.** { *; }