Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minimize Kotlin Standard library Option #4948

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@ abstract class ProguardSettings @Inject constructor(
val obfuscate: Property<Boolean> = objects.notNullProperty(false)
val optimize: Property<Boolean> = objects.notNullProperty(true)
val joinOutputJars: Property<Boolean> = objects.notNullProperty(false)
val minimizeKotlinStandardLibrary: Property<Boolean> = objects.notNullProperty(false)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ abstract class AbstractProguardTask : AbstractComposeDesktopTask() {
@get:Input
val dontoptimize: Property<Boolean?> = objects.nullableProperty()

@get:Optional
@get:Input
val minimizeKotlinStandardLibrary: Property<Boolean?> = objects.nullableProperty()

@get:Optional
@get:Input
val joinOutputJars: Property<Boolean?> = objects.nullableProperty()
Expand Down Expand Up @@ -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[]);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
-keep class kotlin.** { *; }
-keep class org.jetbrains.skia.** { *; }
-keep class org.jetbrains.skiko.** { *; }

Expand Down
13 changes: 13 additions & 0 deletions tutorials/Native_distributions_and_local_execution/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
```