Browse Source

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.
repr_unbound_symbols_knative
Alexey Tsvetkov 1 year ago committed by GitHub
parent
commit
b67dde7295
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/desktop/application/dsl/ProguardSettings.kt
  2. 1
      gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/desktop/application/internal/configureJvmApplication.kt
  3. 8
      gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/desktop/application/tasks/AbstractProguardTask.kt
  4. 2
      gradle-plugins/gradle.properties
  5. 11
      tutorials/Native_distributions_and_local_execution/README.md

1
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 configurationFiles: ConfigurableFileCollection = objects.fileCollection()
val isEnabled: Property<Boolean> = objects.notNullProperty(false) val isEnabled: Property<Boolean> = objects.notNullProperty(false)
val obfuscate: Property<Boolean> = objects.notNullProperty(false) val obfuscate: Property<Boolean> = objects.notNullProperty(false)
val optimize: Property<Boolean> = objects.notNullProperty(true)
} }

1
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, // That's why a task property is follows ProGuard design,
// when our DSL does the opposite. // when our DSL does the opposite.
dontobfuscate.set(settings.obfuscate.map { !it }) dontobfuscate.set(settings.obfuscate.map { !it })
dontoptimize.set(settings.optimize.map { !it })
dependsOn(unpackDefaultResources) dependsOn(unpackDefaultResources)
defaultComposeRulesFile.set(unpackDefaultResources.flatMap { it.resources.defaultComposeProguardRules }) defaultComposeRulesFile.set(unpackDefaultResources.flatMap { it.resources.defaultComposeProguardRules })

8
gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/desktop/application/tasks/AbstractProguardTask.kt

@ -38,6 +38,10 @@ abstract class AbstractProguardTask : AbstractComposeDesktopTask() {
@get:Input @get:Input
val dontobfuscate: Property<Boolean?> = objects.nullableProperty() val dontobfuscate: Property<Boolean?> = objects.nullableProperty()
@get:Optional
@get:Input
val dontoptimize: Property<Boolean?> = objects.nullableProperty()
// todo: DSL for excluding default rules // todo: DSL for excluding default rules
// also consider pulling coroutines rules from coroutines artifact // 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 // 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") writer.writeLn("-dontobfuscate")
} }
if (dontoptimize.orNull == true) {
writer.writeLn("-dontoptimize")
}
writer.writeLn(""" writer.writeLn("""
-keep public class ${mainClass.get()} { -keep public class ${mainClass.get()} {
public static void main(java.lang.String[]); public static void main(java.lang.String[]);

2
gradle-plugins/gradle.properties

@ -2,7 +2,7 @@ org.gradle.parallel=true
kotlin.code.style=official kotlin.code.style=official
# Default version of Compose Libraries used by Gradle plugin # 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. # The latest version of Compose Compiler used by Gradle plugin. Used only in tests/CI.
compose.tests.compiler.version=1.5.0 compose.tests.compiler.version=1.5.0
# The latest version of Kotlin compatible with compose.tests.compiler.version. Used only in tests/CI. # The latest version of Kotlin compatible with compose.tests.compiler.version. Used only in tests/CI.

11
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)
}
}
}
```

Loading…
Cancel
Save