From b67dde7295272b7f18226777e24be98384837dc9 Mon Sep 17 00:00:00 2001 From: Alexey Tsvetkov <654232+AlexeyTsvetkov@users.noreply.github.com> Date: Wed, 26 Jul 2023 12:15:22 +0300 Subject: [PATCH] Add pro guard optimize flag (#3408) * Add DSL flag to control ProGuard's optimizations #3387 * Update default ProGuard version * Revert ProGuard default version to 7.2.2. --- .../desktop/application/dsl/ProguardSettings.kt | 1 + .../application/internal/configureJvmApplication.kt | 1 + .../desktop/application/tasks/AbstractProguardTask.kt | 8 ++++++++ gradle-plugins/gradle.properties | 2 +- .../README.md | 11 +++++++++++ 5 files changed, 22 insertions(+), 1 deletion(-) 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 14a3e27b8f..3a6ef8d84f 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 @@ -22,4 +22,5 @@ abstract class ProguardSettings @Inject constructor( val configurationFiles: ConfigurableFileCollection = objects.fileCollection() val isEnabled: Property = objects.notNullProperty(false) val obfuscate: Property = objects.notNullProperty(false) + val optimize: Property = objects.notNullProperty(true) } 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 5f9a541bd1..36d5194667 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( // That's why a task property is follows ProGuard design, // when our DSL does the opposite. dontobfuscate.set(settings.obfuscate.map { !it }) + dontoptimize.set(settings.optimize.map { !it }) dependsOn(unpackDefaultResources) defaultComposeRulesFile.set(unpackDefaultResources.flatMap { it.resources.defaultComposeProguardRules }) 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 dc8b9187cc..201d5353b5 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 @@ -38,6 +38,10 @@ abstract class AbstractProguardTask : AbstractComposeDesktopTask() { @get:Input val dontobfuscate: Property = objects.nullableProperty() + @get:Optional + @get:Input + val dontoptimize: Property = objects.nullableProperty() + // todo: DSL for excluding default rules // also consider pulling coroutines rules from coroutines artifact // https://github.com/Kotlin/kotlinx.coroutines/blob/master/kotlinx-coroutines-core/jvm/resources/META-INF/proguard/coroutines.pro @@ -109,6 +113,10 @@ abstract class AbstractProguardTask : AbstractComposeDesktopTask() { writer.writeLn("-dontobfuscate") } + if (dontoptimize.orNull == true) { + writer.writeLn("-dontoptimize") + } + writer.writeLn(""" -keep public class ${mainClass.get()} { public static void main(java.lang.String[]); diff --git a/gradle-plugins/gradle.properties b/gradle-plugins/gradle.properties index cb78913521..2e0898d84f 100644 --- a/gradle-plugins/gradle.properties +++ b/gradle-plugins/gradle.properties @@ -2,7 +2,7 @@ org.gradle.parallel=true kotlin.code.style=official # Default version of Compose Libraries used by Gradle plugin -compose.version=1.4.1 +compose.version=1.5.0-dev1122 # The latest version of Compose Compiler used by Gradle plugin. Used only in tests/CI. compose.tests.compiler.version=1.5.0 # The latest version of Kotlin compatible with compose.tests.compiler.version. Used only in tests/CI. diff --git a/tutorials/Native_distributions_and_local_execution/README.md b/tutorials/Native_distributions_and_local_execution/README.md index 90e3791f9c..019d64c120 100755 --- a/tutorials/Native_distributions_and_local_execution/README.md +++ b/tutorials/Native_distributions_and_local_execution/README.md @@ -637,3 +637,14 @@ compose.desktop { } } ``` + +ProGuard's optimizations are enabled by default. To disable them, set the following property via Gradle DSL: +``` +compose.desktop { + application { + buildTypes.release.proguard { + optimize.set(false) + } + } +} +```