From 71a2edc3514a5baf1380173f9fc45e5a0aa32980 Mon Sep 17 00:00:00 2001 From: Ellet Date: Sat, 8 Jun 2024 09:42:36 +0300 Subject: [PATCH 1/5] chore: Update default desktop Proguard rules support minimizing Kotlin standard library option --- .../compose/src/main/resources/default-compose-desktop-rules.pro | 1 - 1 file changed, 1 deletion(-) diff --git a/gradle-plugins/compose/src/main/resources/default-compose-desktop-rules.pro b/gradle-plugins/compose/src/main/resources/default-compose-desktop-rules.pro index 89455d78d32..8f29c99b0b8 100644 --- a/gradle-plugins/compose/src/main/resources/default-compose-desktop-rules.pro +++ b/gradle-plugins/compose/src/main/resources/default-compose-desktop-rules.pro @@ -1,4 +1,3 @@ --keep class kotlin.** { *; } -keep class org.jetbrains.skia.** { *; } -keep class org.jetbrains.skiko.** { *; } From 4749102bce04be796419c5dadefb8988946266dd Mon Sep 17 00:00:00 2001 From: Ellet Date: Sat, 8 Jun 2024 09:45:38 +0300 Subject: [PATCH 2/5] chore: add minimizeKotlinStandardLibrary in ProguardSettings --- .../compose/desktop/application/dsl/ProguardSettings.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/desktop/application/dsl/ProguardSettings.kt b/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/desktop/application/dsl/ProguardSettings.kt index a3459d40d5c..1435033dcb3 100644 --- a/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/desktop/application/dsl/ProguardSettings.kt +++ b/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/desktop/application/dsl/ProguardSettings.kt @@ -24,4 +24,5 @@ abstract class ProguardSettings @Inject constructor( val obfuscate: Property = objects.notNullProperty(false) val optimize: Property = objects.notNullProperty(true) val joinOutputJars: Property = objects.notNullProperty(false) + val minimizeKotlinStandardLibrary: Property = objects.notNullProperty(false) } From d389bd35bb7c24cf8f05aea496544e9d0764fc7a Mon Sep 17 00:00:00 2001 From: Ellet Date: Sat, 8 Jun 2024 09:47:01 +0300 Subject: [PATCH 3/5] feat: add an option to minimize kotlin standard library in AbstractProguardTask --- .../desktop/application/tasks/AbstractProguardTask.kt | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/desktop/application/tasks/AbstractProguardTask.kt b/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/desktop/application/tasks/AbstractProguardTask.kt index fa04502a912..bb5cffafcb8 100644 --- a/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/desktop/application/tasks/AbstractProguardTask.kt +++ b/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/desktop/application/tasks/AbstractProguardTask.kt @@ -42,6 +42,10 @@ abstract class AbstractProguardTask : AbstractComposeDesktopTask() { @get:Input val dontoptimize: Property = objects.nullableProperty() + @get:Optional + @get:Input + val minimizeKotlinStandardLibrary: Property = objects.nullableProperty() + @get:Optional @get:Input val joinOutputJars: Property = objects.nullableProperty() @@ -125,6 +129,10 @@ abstract class AbstractProguardTask : AbstractComposeDesktopTask() { writer.writeLn("-dontoptimize") } + if (minimizeKotlinStandardLibrary.orNull == false) { + writer.writeLn("-keep class kotlin.** { *; }") + } + writer.writeLn(""" -keep public class ${mainClass.get()} { public static void main(java.lang.String[]); From b2460ad2e30846f88dc41651c20158c1f2a0ef90 Mon Sep 17 00:00:00 2001 From: Ellet Date: Sat, 8 Jun 2024 09:48:07 +0300 Subject: [PATCH 4/5] chore: set property minimizeKotlinStandardLibrary of AbstractProguardTask from the ProguardSettings --- .../desktop/application/internal/configureJvmApplication.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/desktop/application/internal/configureJvmApplication.kt b/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/desktop/application/internal/configureJvmApplication.kt index d53ad3dd621..722f548b18a 100644 --- a/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/desktop/application/internal/configureJvmApplication.kt +++ b/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/desktop/application/internal/configureJvmApplication.kt @@ -267,6 +267,7 @@ private fun JvmApplicationContext.configureProguardTask( dontoptimize.set(settings.optimize.map { !it }) joinOutputJars.set(settings.joinOutputJars) + minimizeKotlinStandardLibrary.set(settings.minimizeKotlinStandardLibrary) dependsOn(unpackDefaultResources) defaultComposeRulesFile.set(unpackDefaultResources.flatMap { it.resources.defaultComposeProguardRules }) From 123882f0b933588366acd5744721dd561d8ae976 Mon Sep 17 00:00:00 2001 From: Ellet Date: Sat, 8 Jun 2024 09:49:52 +0300 Subject: [PATCH 5/5] docs(packaging): document the minimizeKotlinStandardLibrary option in the Native distributions tutorial --- .../README.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tutorials/Native_distributions_and_local_execution/README.md b/tutorials/Native_distributions_and_local_execution/README.md index ffc91c4904d..4bed00b4532 100755 --- a/tutorials/Native_distributions_and_local_execution/README.md +++ b/tutorials/Native_distributions_and_local_execution/README.md @@ -663,3 +663,16 @@ compose.desktop { } } ``` + +Minimizing the Kotlin library is disabled by default. +To minimize it, +set the following property via Gradle DSL: +``` +compose.desktop { + application { + buildTypes.release.proguard { + minimizeKotlinStandardLibrary.set(true) + } + } +} +``` \ No newline at end of file