Browse Source

Disable ProGuard's optimizations by default

Resolves #3387
disable-pg-optimization-by-default
Alexey Tsvetkov 1 year ago
parent
commit
51601ad180
  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. 5
      gradle-plugins/compose/src/test/test-projects/application/proguard/src/main/kotlin/Main.kt
  5. 2
      gradle-plugins/gradle.properties
  6. 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 isEnabled: Property<Boolean> = objects.notNullProperty(false)
val obfuscate: Property<Boolean> = objects.notNullProperty(false)
val optimize: Property<Boolean> = objects.notNullProperty(false)
}

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,
// 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 })

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
val dontobfuscate: Property<Boolean?> = objects.nullableProperty()
@get:Optional
@get:Input
val dontoptimize: Property<Boolean?> = 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[]);

5
gradle-plugins/compose/src/test/test-projects/application/proguard/src/main/kotlin/Main.kt

@ -1,3 +1,4 @@
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.shape.CircleShape
@ -25,7 +26,9 @@ object Main {
}
val image = renderComposeScene(height = 10, width = 10) {
mainShape()
AnimatedVisibility(true) {
mainShape()
}
}
val encodedImage = image.encodeToData(EncodedImageFormat.PNG) ?: error("Could not encode image as png")
workingDir.resolve("main-image.actual.png").writeBytes(encodedImage.bytes)

2
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-dev1114
# 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.

11
tutorials/Native_distributions_and_local_execution/README.md

@ -637,3 +637,14 @@ compose.desktop {
}
}
```
ProGuard's optimization is disabled by default since Compose 1.5. To enable it, set the following property via Gradle DSL:
```
compose.desktop {
application {
buildTypes.release.proguard {
optimize.set(true)
}
}
}
```

Loading…
Cancel
Save