-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce ProGuard integration for Compose/Desktop packaging
Resolves #1174
- Loading branch information
1 parent
59d4676
commit 544f773
Showing
54 changed files
with
1,332 additions
and
577 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# Ktor | ||
-keep class io.ktor.** { *; } | ||
-keepclassmembers class io.ktor.** { volatile <fields>; } | ||
-keep class io.ktor.client.engine.cio.** { *; } | ||
-keep class kotlinx.coroutines.** { *; } | ||
-dontwarn kotlinx.atomicfu.** | ||
-dontwarn io.netty.** | ||
-dontwarn com.typesafe.** | ||
-dontwarn org.slf4j.** | ||
|
||
# Obfuscation breaks coroutines/ktor for some reason | ||
-dontobfuscate |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
...src/main/kotlin/org/jetbrains/compose/desktop/application/dsl/JvmApplicationBuildTypes.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* Copyright 2020-2022 JetBrains s.r.o. and respective authors and developers. | ||
* Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE.txt file. | ||
*/ | ||
|
||
package org.jetbrains.compose.desktop.application.dsl | ||
|
||
import org.gradle.api.Action | ||
import org.gradle.api.model.ObjectFactory | ||
import org.jetbrains.compose.desktop.application.internal.new | ||
import javax.inject.Inject | ||
|
||
abstract class JvmApplicationBuildTypes @Inject constructor( | ||
objects: ObjectFactory | ||
) { | ||
/** | ||
* The default build type does not have a classifier | ||
* to preserve compatibility with tasks, existing before | ||
* the introduction of the release build type, | ||
* e.g. we don't want to break existing packageDmg, | ||
* createDistributable tasks after the introduction | ||
* of packageReleaseDmg and createReleaseDistributable tasks. | ||
*/ | ||
internal val default: JvmApplicationBuildType = objects.new("") | ||
|
||
val release: JvmApplicationBuildType = objects.new<JvmApplicationBuildType>("release").apply { | ||
proguard.isEnabled.set(true) | ||
} | ||
fun release(fn: Action<JvmApplicationBuildType>) { | ||
fn.execute(release) | ||
} | ||
} | ||
|
||
abstract class JvmApplicationBuildType @Inject constructor( | ||
/** | ||
* A classifier distinguishes tasks and directories of one build type from another. | ||
* E.g. `release` build type produces packageReleaseDmg task. | ||
*/ | ||
internal val classifier: String, | ||
objects: ObjectFactory, | ||
) { | ||
val proguard: ProguardSettings = objects.new() | ||
fun proguard(fn: Action<ProguardSettings>) { | ||
fn.execute(proguard) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
...compose/src/main/kotlin/org/jetbrains/compose/desktop/application/dsl/ProguardSettings.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* Copyright 2020-2022 JetBrains s.r.o. and respective authors and developers. | ||
* Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE.txt file. | ||
*/ | ||
|
||
package org.jetbrains.compose.desktop.application.dsl | ||
|
||
import org.gradle.api.file.ConfigurableFileCollection | ||
import org.gradle.api.model.ObjectFactory | ||
import org.gradle.api.provider.Property | ||
import org.jetbrains.compose.desktop.application.internal.notNullProperty | ||
import org.jetbrains.compose.desktop.application.internal.nullableProperty | ||
import javax.inject.Inject | ||
|
||
private const val DEFAULT_PROGUARD_VERSION = "7.2.2" | ||
|
||
abstract class ProguardSettings @Inject constructor( | ||
objects: ObjectFactory, | ||
) { | ||
val version: Property<String> = objects.notNullProperty(DEFAULT_PROGUARD_VERSION) | ||
val maxHeapSize: Property<String?> = objects.nullableProperty() | ||
val configurationFiles: ConfigurableFileCollection = objects.fileCollection() | ||
val isEnabled: Property<Boolean> = objects.notNullProperty(false) | ||
} |
44 changes: 0 additions & 44 deletions
44
...src/main/kotlin/org/jetbrains/compose/desktop/application/internal/ConfigurationSource.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
...c/main/kotlin/org/jetbrains/compose/desktop/application/internal/JvmApplicationContext.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* | ||
* Copyright 2020-2022 JetBrains s.r.o. and respective authors and developers. | ||
* Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE.txt file. | ||
*/ | ||
|
||
package org.jetbrains.compose.desktop.application.internal | ||
|
||
import org.gradle.api.Project | ||
import org.gradle.api.Task | ||
import org.gradle.api.file.Directory | ||
import org.gradle.api.provider.Provider | ||
import org.jetbrains.compose.desktop.application.dsl.JvmApplicationBuildType | ||
import org.jetbrains.compose.internal.KOTLIN_JVM_PLUGIN_ID | ||
import org.jetbrains.compose.internal.KOTLIN_MPP_PLUGIN_ID | ||
import org.jetbrains.compose.internal.javaSourceSets | ||
import org.jetbrains.compose.internal.joinDashLowercaseNonEmpty | ||
import org.jetbrains.compose.internal.mppExt | ||
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType | ||
|
||
internal data class JvmApplicationContext( | ||
val project: Project, | ||
private val appInternal: JvmApplicationInternal, | ||
val buildType: JvmApplicationBuildType, | ||
private val taskGroup: String = composeDesktopTaskGroup | ||
) { | ||
val app: JvmApplicationData | ||
get() = appInternal.data | ||
|
||
val appDirName: String | ||
get() = joinDashLowercaseNonEmpty(appInternal.name, buildType.classifier) | ||
|
||
val appTmpDir: Provider<Directory> | ||
get() = project.layout.buildDirectory.dir( | ||
"compose/tmp/$appDirName" | ||
) | ||
|
||
fun <T : Task> T.useAppRuntimeFiles(fn: T.(JvmApplicationRuntimeFiles) -> Unit) { | ||
val runtimeFiles = app.jvmApplicationRuntimeFilesProvider?.jvmApplicationRuntimeFiles(project) | ||
?: JvmApplicationRuntimeFiles( | ||
allRuntimeJars = app.fromFiles, | ||
mainJar = app.mainJar, | ||
taskDependencies = app.dependenciesTaskNames.toTypedArray() | ||
) | ||
runtimeFiles.configureUsageBy(this, fn) | ||
} | ||
|
||
val tasks = JvmTasks(project, buildType, taskGroup) | ||
|
||
val packageNameProvider: Provider<String> | ||
get() = project.provider { appInternal.nativeDistributions.packageName ?: project.name } | ||
|
||
inline fun <reified T> provider(noinline fn: () -> T): Provider<T> = | ||
project.provider(fn) | ||
|
||
fun configureDefaultApp() { | ||
if (project.plugins.hasPlugin(KOTLIN_MPP_PLUGIN_ID)) { | ||
var isJvmTargetConfigured = false | ||
project.mppExt.targets.all { target -> | ||
if (target.platformType == KotlinPlatformType.jvm) { | ||
if (!isJvmTargetConfigured) { | ||
appInternal.from(target) | ||
isJvmTargetConfigured = true | ||
} else { | ||
project.logger.error("w: Default configuration for Compose Desktop Application is disabled: " + | ||
"multiple Kotlin JVM targets definitions are detected. " + | ||
"Specify, which target to use by using `compose.desktop.application.from(kotlinMppTarget)`") | ||
appInternal.disableDefaultConfiguration() | ||
} | ||
} | ||
} | ||
} else if (project.plugins.hasPlugin(KOTLIN_JVM_PLUGIN_ID)) { | ||
val mainSourceSet = project.javaSourceSets.getByName("main") | ||
appInternal.from(mainSourceSet) | ||
} | ||
} | ||
} |
Oops, something went wrong.