Skip to content

Commit

Permalink
Add pro guard optimize flag (#3408)
Browse files Browse the repository at this point in the history
* Add DSL flag to control ProGuard's optimizations

#3387

* Update default ProGuard version

* Revert ProGuard default version to 7.2.2.
  • Loading branch information
AlexeyTsvetkov authored Jul 26, 2023
1 parent a6cdfd8 commit b67dde7
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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(true)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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[]);
Expand Down
2 changes: 1 addition & 1 deletion gradle-plugins/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
11 changes: 11 additions & 0 deletions tutorials/Native_distributions_and_local_execution/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
```

0 comments on commit b67dde7

Please sign in to comment.