From e915ec6ac12b8057ce69d67b220b3dbcdf773ea0 Mon Sep 17 00:00:00 2001 From: Alexey Tsvetkov Date: Mon, 2 Nov 2020 09:42:40 +0300 Subject: [PATCH 1/7] Make AppImage format compatible with all OS Turns out, app-image is not an OS specific format, but a prepackaged image of packaged app --- .../desktop/application/ApplicationPlugin.kt | 72 ++++++++++--------- .../desktop/application/dsl/TargetFormat.kt | 11 ++- .../application/internal/wixToolset.kt | 2 +- .../application/tasks/AbstractJPackageTask.kt | 4 -- 4 files changed, 47 insertions(+), 42 deletions(-) diff --git a/gradle-plugins/compose-desktop-application/src/main/kotlin/org/jetbrains/compose/desktop/application/ApplicationPlugin.kt b/gradle-plugins/compose-desktop-application/src/main/kotlin/org/jetbrains/compose/desktop/application/ApplicationPlugin.kt index 43e226f4bf..bf3a75dd39 100644 --- a/gradle-plugins/compose-desktop-application/src/main/kotlin/org/jetbrains/compose/desktop/application/ApplicationPlugin.kt +++ b/gradle-plugins/compose-desktop-application/src/main/kotlin/org/jetbrains/compose/desktop/application/ApplicationPlugin.kt @@ -12,6 +12,7 @@ import org.jetbrains.compose.desktop.DesktopBasePlugin import org.jetbrains.compose.desktop.DesktopExtension import org.jetbrains.compose.desktop.application.dsl.Application import org.jetbrains.compose.desktop.application.dsl.ConfigurationSource +import org.jetbrains.compose.desktop.application.dsl.TargetFormat import org.jetbrains.compose.desktop.application.internal.OS import org.jetbrains.compose.desktop.application.internal.configureWix import org.jetbrains.compose.desktop.application.internal.currentOS @@ -91,9 +92,44 @@ internal fun Project.configurePackagingTasks(app: Application): TaskProvider + packageName.set(provider { executables.packageName ?: project.name }) + packageDescription.set(provider { executables.description }) + packageCopyright.set(provider { executables.copyright }) + packageVendor.set(provider { executables.vendor }) + packageVersion.set(provider { + executables.version + ?: project.version.toString().takeIf { it != "unspecified" } + }) + } + + destinationDir.set(app.nativeDistributions.outputBaseDir.map { it.dir("${app.name}/${targetFormat.id}") }) + javaHome.set(provider { app.javaHomeOrDefault() }) + + launcherMainJar.set(app.mainJar.orNull) + app._fromFiles.forEach { files.from(it) } + dependsOn(*app._dependenciesTaskNames.toTypedArray()) + + app._configurationSource?.let { configSource -> + dependsOn(configSource.jarTaskName) + files.from(configSource.runtimeClasspath) + launcherMainJar.set(app.mainJar.orElse(configSource.jarTask(project).flatMap { it.archiveFile })) + } + + modules.set(provider { app.nativeDistributions.modules }) + launcherMainClass.set(provider { app.mainClass }) + launcherJvmArgs.set(provider { app.jvmArgs }) + launcherArgs.set(provider { app.args }) +} + +internal fun AbstractJPackageTask.configurePlatformSettings(app: Application) { + when (currentOS) { OS.Linux -> { app.nativeDistributions.linux.also { linux -> linuxShortcut.set(provider { linux.shortcut }) @@ -130,40 +166,8 @@ internal fun AbstractJPackageTask.configurePackagingTask(app: Application) { } } } - - app.nativeDistributions.let { executables -> - packageName.set(provider { executables.packageName ?: project.name }) - packageDescription.set(provider { executables.description }) - packageCopyright.set(provider { executables.copyright }) - packageVendor.set(provider { executables.vendor }) - packageVersion.set(provider { - executables.version - ?: project.version.toString().takeIf { it != "unspecified" } - }) - } - - destinationDir.set(app.nativeDistributions.outputBaseDir.map { it.dir("${app.name}/${targetFormat.id}") }) - javaHome.set(provider { app.javaHomeOrDefault() }) - - launcherMainJar.set(app.mainJar.orNull) - app._fromFiles.forEach { files.from(it) } - dependsOn(*app._dependenciesTaskNames.toTypedArray()) - - app._configurationSource?.let { configSource -> - dependsOn(configSource.jarTaskName) - files.from(configSource.runtimeClasspath) - launcherMainJar.set(app.mainJar.orElse(configSource.jarTask(project).flatMap { it.archiveFile })) - } - - modules.set(provider { app.nativeDistributions.modules }) - launcherMainClass.set(provider { app.mainClass }) - launcherJvmArgs.set(provider { app.jvmArgs }) - launcherArgs.set(provider { app.args }) } -private fun AbstractJPackageTask.jarFromJarTaskByName(jarTaskName: String) = - project.tasks.named(jarTaskName).map { (it as Jar).archiveFile.get() } - private fun Project.configureRunTask(app: Application) { project.tasks.composeTask(taskName("run", app)) { mainClass.set(provider { app.mainClass }) diff --git a/gradle-plugins/compose-desktop-application/src/main/kotlin/org/jetbrains/compose/desktop/application/dsl/TargetFormat.kt b/gradle-plugins/compose-desktop-application/src/main/kotlin/org/jetbrains/compose/desktop/application/dsl/TargetFormat.kt index 43e6a5ea67..f0384d1fd4 100644 --- a/gradle-plugins/compose-desktop-application/src/main/kotlin/org/jetbrains/compose/desktop/application/dsl/TargetFormat.kt +++ b/gradle-plugins/compose-desktop-application/src/main/kotlin/org/jetbrains/compose/desktop/application/dsl/TargetFormat.kt @@ -1,16 +1,21 @@ package org.jetbrains.compose.desktop.application.dsl import org.jetbrains.compose.desktop.application.internal.OS +import org.jetbrains.compose.desktop.application.internal.currentOS enum class TargetFormat( internal val id: String, - internal val os: OS + private vararg val compatibleOSs: OS ) { + AppImage("app-image", *OS.values()), Deb("deb", OS.Linux), Rpm("rpm", OS.Linux), - App("app-image", OS.MacOS), Dmg("dmg", OS.MacOS), Pkg("pkg", OS.MacOS), Exe("exe", OS.Windows), - Msi("msi", OS.Windows) + Msi("msi", OS.Windows); + + val isCompatibleWithCurrentOS: Boolean by lazy { isCompatibleWith(currentOS) } + + internal fun isCompatibleWith(targetOS: OS): Boolean = targetOS in compatibleOSs } \ No newline at end of file diff --git a/gradle-plugins/compose-desktop-application/src/main/kotlin/org/jetbrains/compose/desktop/application/internal/wixToolset.kt b/gradle-plugins/compose-desktop-application/src/main/kotlin/org/jetbrains/compose/desktop/application/internal/wixToolset.kt index 4e7e638c7f..80a114c627 100644 --- a/gradle-plugins/compose-desktop-application/src/main/kotlin/org/jetbrains/compose/desktop/application/internal/wixToolset.kt +++ b/gradle-plugins/compose-desktop-application/src/main/kotlin/org/jetbrains/compose/desktop/application/internal/wixToolset.kt @@ -48,7 +48,7 @@ internal fun Project.configureWix() { private fun Project.eachWindowsPackageTask(fn: AbstractJPackageTask.() -> Unit) { tasks.withType(AbstractJPackageTask::class.java).configureEach { packageTask -> - if (packageTask.targetOS == OS.Windows) { + if (packageTask.targetFormat.isCompatibleWith(OS.Windows)) { packageTask.fn() } } diff --git a/gradle-plugins/compose-desktop-application/src/main/kotlin/org/jetbrains/compose/desktop/application/tasks/AbstractJPackageTask.kt b/gradle-plugins/compose-desktop-application/src/main/kotlin/org/jetbrains/compose/desktop/application/tasks/AbstractJPackageTask.kt index 064170add9..442df40e83 100644 --- a/gradle-plugins/compose-desktop-application/src/main/kotlin/org/jetbrains/compose/desktop/application/tasks/AbstractJPackageTask.kt +++ b/gradle-plugins/compose-desktop-application/src/main/kotlin/org/jetbrains/compose/desktop/application/tasks/AbstractJPackageTask.kt @@ -32,10 +32,6 @@ abstract class AbstractJPackageTask @Inject constructor( objects: ObjectFactory, providers: ProviderFactory ) : DefaultTask() { - @get:Input - internal val targetOS: OS - get() = targetFormat.os - @get:InputFiles val files: ConfigurableFileCollection = objects.fileCollection() From b0f038d833a3ae9abbf8e276f3ad7a5d6c985be3 Mon Sep 17 00:00:00 2001 From: Alexey Tsvetkov Date: Mon, 2 Nov 2020 09:53:00 +0300 Subject: [PATCH 2/7] Minor: remove unused imports --- .../compose/desktop/application/ApplicationPlugin.kt | 5 ----- 1 file changed, 5 deletions(-) diff --git a/gradle-plugins/compose-desktop-application/src/main/kotlin/org/jetbrains/compose/desktop/application/ApplicationPlugin.kt b/gradle-plugins/compose-desktop-application/src/main/kotlin/org/jetbrains/compose/desktop/application/ApplicationPlugin.kt index bf3a75dd39..bdc90e3f63 100644 --- a/gradle-plugins/compose-desktop-application/src/main/kotlin/org/jetbrains/compose/desktop/application/ApplicationPlugin.kt +++ b/gradle-plugins/compose-desktop-application/src/main/kotlin/org/jetbrains/compose/desktop/application/ApplicationPlugin.kt @@ -1,17 +1,14 @@ package org.jetbrains.compose.desktop.application import org.gradle.api.* -import org.gradle.api.file.FileCollection import org.gradle.api.plugins.JavaPluginConvention import org.gradle.api.tasks.JavaExec import org.gradle.api.tasks.TaskContainer import org.gradle.api.tasks.TaskProvider -import org.gradle.jvm.tasks.Jar import org.jetbrains.compose.ComposeExtension import org.jetbrains.compose.desktop.DesktopBasePlugin import org.jetbrains.compose.desktop.DesktopExtension import org.jetbrains.compose.desktop.application.dsl.Application -import org.jetbrains.compose.desktop.application.dsl.ConfigurationSource import org.jetbrains.compose.desktop.application.dsl.TargetFormat import org.jetbrains.compose.desktop.application.internal.OS import org.jetbrains.compose.desktop.application.internal.configureWix @@ -19,9 +16,7 @@ import org.jetbrains.compose.desktop.application.internal.currentOS import org.jetbrains.compose.desktop.application.internal.provider import org.jetbrains.compose.desktop.application.tasks.AbstractJPackageTask import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension -import org.jetbrains.kotlin.gradle.plugin.KotlinCompilationToRunnableFiles import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType -import org.jetbrains.kotlin.gradle.plugin.KotlinTarget import java.io.File import java.util.* From 3b7835fb4a9cce095d3153ff61757b31a850e90e Mon Sep 17 00:00:00 2001 From: Alexey Tsvetkov Date: Tue, 3 Nov 2020 14:17:29 +0300 Subject: [PATCH 3/7] Merge compose.desktop.application plugin with compose plugin This change removes `org.jetbrains.compose.desktop.application` plugin id in favor of doing everything in `org.jetbrains.compose`. The change simplifies configuring Compose Desktop projects. Now, just one plugin dependency is needed. To avoid task name conflicts with common task names such as `package` and `run`, the plugin creates tasks lazily only if `application` block/property is used in a script. --- examples/imageviewer/build.gradle.kts | 4 +- examples/imageviewer/desktop/build.gradle.kts | 1 - .../build.gradle.kts | 47 ------------------- .../jetbrains/compose/ComposeBasePlugin.kt | 10 ---- .../compose/desktop/DesktopBasePlugin.kt | 14 ------ .../compose/desktop/DesktopExtension.kt | 5 -- gradle-plugins/compose/build.gradle.kts | 30 +++++++++++- .../org/jetbrains/compose/ComposeExtension.kt | 0 .../org/jetbrains/compose/ComposePlugin.kt | 11 +++++ .../compose/desktop/DesktopExtension.kt | 20 ++++++++ .../desktop/application/dsl/Application.kt | 5 +- .../application/dsl/ConfigurationSource.kt | 0 .../application/dsl/NativeDistributions.kt | 0 .../application/dsl/PlatformSettings.kt | 0 .../desktop/application/dsl/TargetFormat.kt | 0 .../application/internal/cliArgUtils.kt | 0 .../internal/configureApplication.kt} | 42 +++++------------ .../desktop/application/internal/dslUtils.kt | 0 .../desktop/application/internal/osUtils.kt | 0 .../application/internal/wixToolset.kt | 0 .../application/tasks/AbstractJPackageTask.kt | 0 gradle-plugins/settings.gradle.kts | 3 +- .../README.md | 12 ++--- 23 files changed, 87 insertions(+), 117 deletions(-) delete mode 100644 gradle-plugins/compose-desktop-application/build.gradle.kts delete mode 100644 gradle-plugins/compose-desktop-application/src/main/kotlin/org/jetbrains/compose/ComposeBasePlugin.kt delete mode 100644 gradle-plugins/compose-desktop-application/src/main/kotlin/org/jetbrains/compose/desktop/DesktopBasePlugin.kt delete mode 100644 gradle-plugins/compose-desktop-application/src/main/kotlin/org/jetbrains/compose/desktop/DesktopExtension.kt rename gradle-plugins/{compose-desktop-application => compose}/src/main/kotlin/org/jetbrains/compose/ComposeExtension.kt (100%) create mode 100644 gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/desktop/DesktopExtension.kt rename gradle-plugins/{compose-desktop-application => compose}/src/main/kotlin/org/jetbrains/compose/desktop/application/dsl/Application.kt (93%) rename gradle-plugins/{compose-desktop-application => compose}/src/main/kotlin/org/jetbrains/compose/desktop/application/dsl/ConfigurationSource.kt (100%) rename gradle-plugins/{compose-desktop-application => compose}/src/main/kotlin/org/jetbrains/compose/desktop/application/dsl/NativeDistributions.kt (100%) rename gradle-plugins/{compose-desktop-application => compose}/src/main/kotlin/org/jetbrains/compose/desktop/application/dsl/PlatformSettings.kt (100%) rename gradle-plugins/{compose-desktop-application => compose}/src/main/kotlin/org/jetbrains/compose/desktop/application/dsl/TargetFormat.kt (100%) rename gradle-plugins/{compose-desktop-application => compose}/src/main/kotlin/org/jetbrains/compose/desktop/application/internal/cliArgUtils.kt (100%) rename gradle-plugins/{compose-desktop-application/src/main/kotlin/org/jetbrains/compose/desktop/application/ApplicationPlugin.kt => compose/src/main/kotlin/org/jetbrains/compose/desktop/application/internal/configureApplication.kt} (80%) rename gradle-plugins/{compose-desktop-application => compose}/src/main/kotlin/org/jetbrains/compose/desktop/application/internal/dslUtils.kt (100%) rename gradle-plugins/{compose-desktop-application => compose}/src/main/kotlin/org/jetbrains/compose/desktop/application/internal/osUtils.kt (100%) rename gradle-plugins/{compose-desktop-application => compose}/src/main/kotlin/org/jetbrains/compose/desktop/application/internal/wixToolset.kt (100%) rename gradle-plugins/{compose-desktop-application => compose}/src/main/kotlin/org/jetbrains/compose/desktop/application/tasks/AbstractJPackageTask.kt (100%) diff --git a/examples/imageviewer/build.gradle.kts b/examples/imageviewer/build.gradle.kts index 3fb2dd621d..04d672ff92 100755 --- a/examples/imageviewer/build.gradle.kts +++ b/examples/imageviewer/build.gradle.kts @@ -1,5 +1,8 @@ buildscript { repositories { + mavenLocal().mavenContent { + includeModule("org.jetbrains.compose", "compose-gradle-plugin") + } google() jcenter() maven("https://maven.pkg.jetbrains.space/public/p/compose/dev") @@ -7,7 +10,6 @@ buildscript { dependencies { classpath("org.jetbrains.compose:compose-gradle-plugin:0.1.0-m1-build57") - classpath("org.jetbrains.compose:compose-desktop-application-gradle-plugin:0.1.0-m1-build57") classpath("com.android.tools.build:gradle:4.0.1") classpath(kotlin("gradle-plugin", version = "1.4.0")) } diff --git a/examples/imageviewer/desktop/build.gradle.kts b/examples/imageviewer/desktop/build.gradle.kts index a7475d7354..e79030a751 100755 --- a/examples/imageviewer/desktop/build.gradle.kts +++ b/examples/imageviewer/desktop/build.gradle.kts @@ -4,7 +4,6 @@ import org.jetbrains.compose.desktop.application.dsl.TargetFormat plugins { kotlin("multiplatform") // kotlin("jvm") doesn't work well in IDEA/AndroidStudio (https://github.com/JetBrains/compose-jb/issues/22) id("org.jetbrains.compose") - id("org.jetbrains.compose.desktop.application") } kotlin { diff --git a/gradle-plugins/compose-desktop-application/build.gradle.kts b/gradle-plugins/compose-desktop-application/build.gradle.kts deleted file mode 100644 index d664328f6b..0000000000 --- a/gradle-plugins/compose-desktop-application/build.gradle.kts +++ /dev/null @@ -1,47 +0,0 @@ -import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar - -plugins { - kotlin("jvm") - id("com.gradle.plugin-publish") - id("java-gradle-plugin") - id("maven-publish") - id("com.github.johnrengelman.shadow") version "6.1.0" -} - -gradlePluginConfig { - pluginId = "org.jetbrains.compose.desktop.application" - artifactId = "compose-desktop-application-gradle-plugin" - displayName = "JetBrains Compose Desktop Application Plugin" - description = "Plugin for creating native distributions and run configurations" - implementationClass = "org.jetbrains.compose.desktop.application.ApplicationPlugin" -} - -val embedded by configurations.creating - -dependencies { - fun embeddedCompileOnly(dep: String) { - compileOnly(dep) - embedded(dep) - } - - compileOnly(gradleApi()) - compileOnly(kotlin("gradle-plugin-api")) - compileOnly(kotlin("gradle-plugin")) - // include relocated download task to avoid potential runtime conflicts - embeddedCompileOnly("de.undercouch:gradle-download-task:4.1.1") -} - -val shadow = tasks.named("shadowJar") { - val fromPackage = "de.undercouch" - val toPackage = "org.jetbrains.compose.$fromPackage" - relocate(fromPackage, toPackage) - archiveClassifier.set("shadow") - configurations = listOf(embedded) - exclude("META-INF/gradle-plugins/de.undercouch.download.properties") -} - -val jar = tasks.named("jar") { - dependsOn(shadow) - from(zipTree(shadow.get().archiveFile)) - this.duplicatesStrategy = DuplicatesStrategy.INCLUDE -} \ No newline at end of file diff --git a/gradle-plugins/compose-desktop-application/src/main/kotlin/org/jetbrains/compose/ComposeBasePlugin.kt b/gradle-plugins/compose-desktop-application/src/main/kotlin/org/jetbrains/compose/ComposeBasePlugin.kt deleted file mode 100644 index 2da769ba9b..0000000000 --- a/gradle-plugins/compose-desktop-application/src/main/kotlin/org/jetbrains/compose/ComposeBasePlugin.kt +++ /dev/null @@ -1,10 +0,0 @@ -package org.jetbrains.compose - -import org.gradle.api.Plugin -import org.gradle.api.Project - -open class ComposeBasePlugin : Plugin { - override fun apply(project: Project) { - project.extensions.create("compose", ComposeExtension::class.java) - } -} \ No newline at end of file diff --git a/gradle-plugins/compose-desktop-application/src/main/kotlin/org/jetbrains/compose/desktop/DesktopBasePlugin.kt b/gradle-plugins/compose-desktop-application/src/main/kotlin/org/jetbrains/compose/desktop/DesktopBasePlugin.kt deleted file mode 100644 index 99b4550567..0000000000 --- a/gradle-plugins/compose-desktop-application/src/main/kotlin/org/jetbrains/compose/desktop/DesktopBasePlugin.kt +++ /dev/null @@ -1,14 +0,0 @@ -package org.jetbrains.compose.desktop - -import org.gradle.api.Plugin -import org.gradle.api.Project -import org.jetbrains.compose.ComposeBasePlugin -import org.jetbrains.compose.ComposeExtension - -open class DesktopBasePlugin : Plugin { - override fun apply(project: Project) { - project.plugins.apply(ComposeBasePlugin::class.java) - val composeExt = project.extensions.getByType(ComposeExtension::class.java) - composeExt.extensions.create("desktop", DesktopExtension::class.java) - } -} \ No newline at end of file diff --git a/gradle-plugins/compose-desktop-application/src/main/kotlin/org/jetbrains/compose/desktop/DesktopExtension.kt b/gradle-plugins/compose-desktop-application/src/main/kotlin/org/jetbrains/compose/desktop/DesktopExtension.kt deleted file mode 100644 index ac192ca6b7..0000000000 --- a/gradle-plugins/compose-desktop-application/src/main/kotlin/org/jetbrains/compose/desktop/DesktopExtension.kt +++ /dev/null @@ -1,5 +0,0 @@ -package org.jetbrains.compose.desktop - -import org.gradle.api.plugins.ExtensionAware - -abstract class DesktopExtension : ExtensionAware \ No newline at end of file diff --git a/gradle-plugins/compose/build.gradle.kts b/gradle-plugins/compose/build.gradle.kts index e23cd97e05..2fb7318846 100644 --- a/gradle-plugins/compose/build.gradle.kts +++ b/gradle-plugins/compose/build.gradle.kts @@ -1,9 +1,12 @@ +import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar + plugins { kotlin("jvm") id("de.fuerstenau.buildconfig") id("com.gradle.plugin-publish") id("java-gradle-plugin") id("maven-publish") + id("com.github.johnrengelman.shadow") version "6.1.0" } gradlePluginConfig { @@ -20,9 +23,34 @@ buildConfig { buildConfigField("String", "composeVersion", BuildProperties.composeVersion) } +val embedded by configurations.creating + dependencies { compileOnly(gradleApi()) compileOnly(localGroovy()) - compileOnly("org.jetbrains.kotlin:kotlin-gradle-plugin") + compileOnly(kotlin("gradle-plugin-api")) + compileOnly(kotlin("gradle-plugin")) testImplementation(gradleTestKit()) + + fun embeddedCompileOnly(dep: String) { + compileOnly(dep) + embedded(dep) + } + // include relocated download task to avoid potential runtime conflicts + embeddedCompileOnly("de.undercouch:gradle-download-task:4.1.1") +} + +val shadow = tasks.named("shadowJar") { + val fromPackage = "de.undercouch" + val toPackage = "org.jetbrains.compose.$fromPackage" + relocate(fromPackage, toPackage) + archiveClassifier.set("shadow") + configurations = listOf(embedded) + exclude("META-INF/gradle-plugins/de.undercouch.download.properties") +} + +val jar = tasks.named("jar") { + dependsOn(shadow) + from(zipTree(shadow.get().archiveFile)) + this.duplicatesStrategy = DuplicatesStrategy.INCLUDE } diff --git a/gradle-plugins/compose-desktop-application/src/main/kotlin/org/jetbrains/compose/ComposeExtension.kt b/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/ComposeExtension.kt similarity index 100% rename from gradle-plugins/compose-desktop-application/src/main/kotlin/org/jetbrains/compose/ComposeExtension.kt rename to gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/ComposeExtension.kt diff --git a/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/ComposePlugin.kt b/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/ComposePlugin.kt index ef90481ab2..546b6212ce 100644 --- a/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/ComposePlugin.kt +++ b/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/ComposePlugin.kt @@ -5,6 +5,8 @@ package org.jetbrains.compose import org.gradle.api.Plugin import org.gradle.api.Project import org.gradle.api.artifacts.dsl.DependencyHandler +import org.jetbrains.compose.desktop.DesktopExtension +import org.jetbrains.compose.desktop.application.internal.configureApplicationImpl import org.jetbrains.kotlin.gradle.plugin.KotlinDependencyHandler import org.jetbrains.kotlin.gradle.tasks.KotlinCompile @@ -12,7 +14,16 @@ private val composeVersion get() = ComposeBuildConfig.composeVersion class ComposePlugin : Plugin { override fun apply(project: Project) { + val composeExtension = project.extensions.create("compose", ComposeExtension::class.java) + val desktopExtension = composeExtension.extensions.create("desktop", DesktopExtension::class.java) + project.afterEvaluate { + if (desktopExtension._isApplicationInitialized) { + // If application object was not accessed in a script, + // we want to avoid creating tasks like package, run, etc. to avoid conflicts with other plugins + configureApplicationImpl(project, desktopExtension.application) + } + project.dependencies.add( "kotlinCompilerPluginClasspath", "org.jetbrains.compose.compiler:compiler:$composeVersion" diff --git a/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/desktop/DesktopExtension.kt b/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/desktop/DesktopExtension.kt new file mode 100644 index 0000000000..bd5cd52ce1 --- /dev/null +++ b/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/desktop/DesktopExtension.kt @@ -0,0 +1,20 @@ +package org.jetbrains.compose.desktop + +import org.gradle.api.model.ObjectFactory +import org.gradle.api.plugins.ExtensionAware +import org.jetbrains.compose.desktop.application.dsl.Application +import javax.inject.Inject + +abstract class DesktopExtension @Inject constructor(private val objectFactory: ObjectFactory) : ExtensionAware { + internal var _isApplicationInitialized = false + private set + + val application: Application by lazy { + _isApplicationInitialized = true + objectFactory.newInstance(Application::class.java, "main") + } + + fun application(fn: Application.() -> Unit) { + application.fn() + } +} diff --git a/gradle-plugins/compose-desktop-application/src/main/kotlin/org/jetbrains/compose/desktop/application/dsl/Application.kt b/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/desktop/application/dsl/Application.kt similarity index 93% rename from gradle-plugins/compose-desktop-application/src/main/kotlin/org/jetbrains/compose/desktop/application/dsl/Application.kt rename to gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/desktop/application/dsl/Application.kt index 874aa2faf7..9833ce2c35 100644 --- a/gradle-plugins/compose-desktop-application/src/main/kotlin/org/jetbrains/compose/desktop/application/dsl/Application.kt +++ b/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/desktop/application/dsl/Application.kt @@ -16,6 +16,9 @@ open class Application @Inject constructor( objects: ObjectFactory ) { internal var _configurationSource: ConfigurationSource? = null + private set + internal var _isDefaultConfigurationEnabled = true + private set internal val _fromFiles = objects.fileCollection() internal val _dependenciesTaskNames = ArrayList() @@ -28,7 +31,7 @@ open class Application @Inject constructor( _configurationSource = ConfigurationSource.KotlinMppTarget(from) } fun disableDefaultConfiguration() { - _configurationSource = null + _isDefaultConfigurationEnabled = false } fun fromFiles(vararg files: Any) { diff --git a/gradle-plugins/compose-desktop-application/src/main/kotlin/org/jetbrains/compose/desktop/application/dsl/ConfigurationSource.kt b/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/desktop/application/dsl/ConfigurationSource.kt similarity index 100% rename from gradle-plugins/compose-desktop-application/src/main/kotlin/org/jetbrains/compose/desktop/application/dsl/ConfigurationSource.kt rename to gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/desktop/application/dsl/ConfigurationSource.kt diff --git a/gradle-plugins/compose-desktop-application/src/main/kotlin/org/jetbrains/compose/desktop/application/dsl/NativeDistributions.kt b/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/desktop/application/dsl/NativeDistributions.kt similarity index 100% rename from gradle-plugins/compose-desktop-application/src/main/kotlin/org/jetbrains/compose/desktop/application/dsl/NativeDistributions.kt rename to gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/desktop/application/dsl/NativeDistributions.kt diff --git a/gradle-plugins/compose-desktop-application/src/main/kotlin/org/jetbrains/compose/desktop/application/dsl/PlatformSettings.kt b/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/desktop/application/dsl/PlatformSettings.kt similarity index 100% rename from gradle-plugins/compose-desktop-application/src/main/kotlin/org/jetbrains/compose/desktop/application/dsl/PlatformSettings.kt rename to gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/desktop/application/dsl/PlatformSettings.kt diff --git a/gradle-plugins/compose-desktop-application/src/main/kotlin/org/jetbrains/compose/desktop/application/dsl/TargetFormat.kt b/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/desktop/application/dsl/TargetFormat.kt similarity index 100% rename from gradle-plugins/compose-desktop-application/src/main/kotlin/org/jetbrains/compose/desktop/application/dsl/TargetFormat.kt rename to gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/desktop/application/dsl/TargetFormat.kt diff --git a/gradle-plugins/compose-desktop-application/src/main/kotlin/org/jetbrains/compose/desktop/application/internal/cliArgUtils.kt b/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/desktop/application/internal/cliArgUtils.kt similarity index 100% rename from gradle-plugins/compose-desktop-application/src/main/kotlin/org/jetbrains/compose/desktop/application/internal/cliArgUtils.kt rename to gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/desktop/application/internal/cliArgUtils.kt diff --git a/gradle-plugins/compose-desktop-application/src/main/kotlin/org/jetbrains/compose/desktop/application/ApplicationPlugin.kt b/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/desktop/application/internal/configureApplication.kt similarity index 80% rename from gradle-plugins/compose-desktop-application/src/main/kotlin/org/jetbrains/compose/desktop/application/ApplicationPlugin.kt rename to gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/desktop/application/internal/configureApplication.kt index bdc90e3f63..4f044af03d 100644 --- a/gradle-plugins/compose-desktop-application/src/main/kotlin/org/jetbrains/compose/desktop/application/ApplicationPlugin.kt +++ b/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/desktop/application/internal/configureApplication.kt @@ -1,49 +1,33 @@ -package org.jetbrains.compose.desktop.application +package org.jetbrains.compose.desktop.application.internal import org.gradle.api.* import org.gradle.api.plugins.JavaPluginConvention import org.gradle.api.tasks.JavaExec import org.gradle.api.tasks.TaskContainer import org.gradle.api.tasks.TaskProvider -import org.jetbrains.compose.ComposeExtension -import org.jetbrains.compose.desktop.DesktopBasePlugin -import org.jetbrains.compose.desktop.DesktopExtension import org.jetbrains.compose.desktop.application.dsl.Application import org.jetbrains.compose.desktop.application.dsl.TargetFormat -import org.jetbrains.compose.desktop.application.internal.OS -import org.jetbrains.compose.desktop.application.internal.configureWix -import org.jetbrains.compose.desktop.application.internal.currentOS -import org.jetbrains.compose.desktop.application.internal.provider import org.jetbrains.compose.desktop.application.tasks.AbstractJPackageTask import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType import java.io.File import java.util.* -private const val PLUGIN_ID = "org.jetbrains.compose.desktop.application" - // todo: multiple launchers // todo: file associations // todo: use workers -@Suppress("unused") // Gradle plugin entry point -open class ApplicationPlugin : Plugin { - override fun apply(project: Project) { - project.plugins.apply(DesktopBasePlugin::class.java) - val composeExt = project.extensions.getByType(ComposeExtension::class.java) - val desktopExt = composeExt.extensions.getByType(DesktopExtension::class.java) - val mainApplication = project.objects.newInstance(Application::class.java, "main") - desktopExt.extensions.add("application", mainApplication) - project.plugins.withId("org.jetbrains.kotlin.jvm") { - val mainSourceSet = project.convention.getPlugin(JavaPluginConvention::class.java).sourceSets.getByName("main") - mainApplication.from(mainSourceSet) - } - project.plugins.withId("org.jetbrains.kotlin.multiplatform") { - project.configureFromMppPlugin(mainApplication) - } - project.afterEvaluate { - project.configurePackagingTasks(listOf(mainApplication)) - project.configureWix() +fun configureApplicationImpl(project: Project, app: Application) { + project.afterEvaluate { + if (app._isDefaultConfigurationEnabled) { + if (project.plugins.hasPlugin("org.jetbrains.kotlin.multiplatform")) { + project.configureFromMppPlugin(app) + } else if (project.plugins.hasPlugin("org.jetbrains.kotlin.jvm")) { + val mainSourceSet = project.convention.getPlugin(JavaPluginConvention::class.java).sourceSets.getByName("main") + app.from(mainSourceSet) + } } + project.configurePackagingTasks(listOf(app)) + project.configureWix() } } @@ -56,7 +40,7 @@ internal fun Project.configureFromMppPlugin(mainApplication: Application) { mainApplication.from(target) isJvmTargetConfigured = true } else { - logger.error("w: Default configuration for '$PLUGIN_ID' is disabled: " + + 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)`") mainApplication.disableDefaultConfiguration() diff --git a/gradle-plugins/compose-desktop-application/src/main/kotlin/org/jetbrains/compose/desktop/application/internal/dslUtils.kt b/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/desktop/application/internal/dslUtils.kt similarity index 100% rename from gradle-plugins/compose-desktop-application/src/main/kotlin/org/jetbrains/compose/desktop/application/internal/dslUtils.kt rename to gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/desktop/application/internal/dslUtils.kt diff --git a/gradle-plugins/compose-desktop-application/src/main/kotlin/org/jetbrains/compose/desktop/application/internal/osUtils.kt b/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/desktop/application/internal/osUtils.kt similarity index 100% rename from gradle-plugins/compose-desktop-application/src/main/kotlin/org/jetbrains/compose/desktop/application/internal/osUtils.kt rename to gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/desktop/application/internal/osUtils.kt diff --git a/gradle-plugins/compose-desktop-application/src/main/kotlin/org/jetbrains/compose/desktop/application/internal/wixToolset.kt b/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/desktop/application/internal/wixToolset.kt similarity index 100% rename from gradle-plugins/compose-desktop-application/src/main/kotlin/org/jetbrains/compose/desktop/application/internal/wixToolset.kt rename to gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/desktop/application/internal/wixToolset.kt diff --git a/gradle-plugins/compose-desktop-application/src/main/kotlin/org/jetbrains/compose/desktop/application/tasks/AbstractJPackageTask.kt b/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/desktop/application/tasks/AbstractJPackageTask.kt similarity index 100% rename from gradle-plugins/compose-desktop-application/src/main/kotlin/org/jetbrains/compose/desktop/application/tasks/AbstractJPackageTask.kt rename to gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/desktop/application/tasks/AbstractJPackageTask.kt diff --git a/gradle-plugins/settings.gradle.kts b/gradle-plugins/settings.gradle.kts index 0a5f35c9d2..198979339b 100644 --- a/gradle-plugins/settings.gradle.kts +++ b/gradle-plugins/settings.gradle.kts @@ -5,5 +5,4 @@ pluginManagement { } } -include(":compose") -include(":compose-desktop-application") \ No newline at end of file +include(":compose") \ No newline at end of file diff --git a/tutorials/Native_distributions_and_local_execution/README.md b/tutorials/Native_distributions_and_local_execution/README.md index 44b96b8669..4865181e8b 100755 --- a/tutorials/Native_distributions_and_local_execution/README.md +++ b/tutorials/Native_distributions_and_local_execution/README.md @@ -5,10 +5,9 @@ In this tutorial, we'll show you how to create native distributions (installers/packages) for all the supported systems. We will also demonstrate how to run an application locally with the same settings as for distributions. -## Desktop application Gradle plugin +## Gradle plugin -`org.jetbrains.compose.desktop.application` -simplifies the packaging of applications into native distributions and running an application locally. +`org.jetbrains.compose` Gradle plugin simplifies the packaging of applications into native distributions and running an application locally. Currently, the plugin uses [jpackage](https://openjdk.java.net/jeps/343) for packaging self-contained applications. ## Basic usage @@ -26,7 +25,6 @@ import org.jetbrains.compose.desktop.application.dsl.TargetFormat plugins { kotlin("jvm") id("org.jetbrains.compose") - id("org.jetbrains.compose.desktop.application") } dependencies { @@ -53,6 +51,8 @@ Tasks that are not compatible with the current OS are skipped by default. aggregating all package tasks for an application. * `run` is used to run an app locally. You need to define a `mainClass` — an fq-name of a class, containing the `main` function. + +Note, that the tasks are created only if the `application` block/property is used in a script. After a build, output binaries can be found in `${project.buildDir}/compose/binaries`. @@ -144,7 +144,7 @@ If the default configuration is ambiguous or not sufficient, the plugin can be c ```kotlin plugins { kotlin("jvm") - id("org.jetbrains.compose.desktop.application") + id("org.jetbrains.compose") } val customSourceSet = sourceSets.create("customSourceSet") @@ -158,7 +158,7 @@ compose.desktop { ```kotlin plugins { kotlin("multiplatform") - id("org.jetbrains.compose.desktop.application") + id("org.jetbrains.compose") } kotlin { From 37cc9665c14f184fea69add839ec7f3ae13b0c00 Mon Sep 17 00:00:00 2001 From: Alexey Tsvetkov Date: Tue, 3 Nov 2020 15:37:15 +0300 Subject: [PATCH 4/7] Log distribution output path --- .../compose/desktop/application/dsl/TargetFormat.kt | 6 ++++++ .../desktop/application/tasks/AbstractJPackageTask.kt | 7 +++++++ 2 files changed, 13 insertions(+) diff --git a/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/desktop/application/dsl/TargetFormat.kt b/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/desktop/application/dsl/TargetFormat.kt index f0384d1fd4..2f28ee1d4b 100644 --- a/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/desktop/application/dsl/TargetFormat.kt +++ b/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/desktop/application/dsl/TargetFormat.kt @@ -18,4 +18,10 @@ enum class TargetFormat( val isCompatibleWithCurrentOS: Boolean by lazy { isCompatibleWith(currentOS) } internal fun isCompatibleWith(targetOS: OS): Boolean = targetOS in compatibleOSs + + val fileExt: String + get() { + check(this != AppImage) { "$this cannot have a file extension" } + return ".$id" + } } \ No newline at end of file diff --git a/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/desktop/application/tasks/AbstractJPackageTask.kt b/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/desktop/application/tasks/AbstractJPackageTask.kt index 442df40e83..dcb651820b 100644 --- a/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/desktop/application/tasks/AbstractJPackageTask.kt +++ b/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/desktop/application/tasks/AbstractJPackageTask.kt @@ -292,6 +292,13 @@ abstract class AbstractJPackageTask @Inject constructor( exec.executable = jpackage.absolutePath exec.setArgs(listOf("@${argsFile.absolutePath}")) }.assertNormalExitValue() + + val destinationDirFile = destinationDir.asFile.get() + val finalLocation = when (targetFormat) { + TargetFormat.AppImage -> destinationDirFile + else -> destinationDirFile.walk().first { it.isFile && it.name.endsWith(targetFormat.fileExt) } + } + logger.lifecycle("The distribution is written to ${finalLocation.canonicalPath}") } finally { tmpDir.deleteRecursively() } From 332d57ae332f046522b421c88cef6a4c7f630fa8 Mon Sep 17 00:00:00 2001 From: Alexey Tsvetkov Date: Tue, 3 Nov 2020 15:39:05 +0300 Subject: [PATCH 5/7] Allow overriding COMPOSE_GRADLE_PLUGIN_COMPOSE_VERSION via Gradle property Gradle properties are more convenient for local builds --- gradle-plugins/build.gradle.kts | 2 +- .../buildSrc/src/main/kotlin/BuildProperties.kt | 11 +++++++---- gradle-plugins/compose/build.gradle.kts | 2 +- gradle-plugins/gradle.properties | 2 ++ 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/gradle-plugins/build.gradle.kts b/gradle-plugins/build.gradle.kts index c5231d8e58..92ae07160a 100644 --- a/gradle-plugins/build.gradle.kts +++ b/gradle-plugins/build.gradle.kts @@ -8,7 +8,7 @@ plugins { subprojects { group = BuildProperties.group - version = BuildProperties.version + version = BuildProperties.deployVersion(project) repositories { maven("https://dl.bintray.com/kotlin/kotlin-dev") diff --git a/gradle-plugins/buildSrc/src/main/kotlin/BuildProperties.kt b/gradle-plugins/buildSrc/src/main/kotlin/BuildProperties.kt index 707a507402..1811562002 100644 --- a/gradle-plugins/buildSrc/src/main/kotlin/BuildProperties.kt +++ b/gradle-plugins/buildSrc/src/main/kotlin/BuildProperties.kt @@ -1,11 +1,14 @@ +import org.gradle.api.Project + // "Global" properties object BuildProperties { const val name = "JetBrains Compose Plugin" const val group = "org.jetbrains.compose" const val website = "https://jetbrains.org/compose" const val vcs = "https://github.com/JetBrains/compose-jb" - val composeVersion: String - get() = System.getenv("COMPOSE_GRADLE_PLUGIN_COMPOSE_VERSION") ?: "0.1.0-SNAPSHOT" - val version: String - get() = System.getenv("COMPOSE_GRADLE_PLUGIN_VERSION") ?: composeVersion + fun composeVersion(project: Project): String = + project.findProperty("compose.version") as? String + ?: System.getenv("COMPOSE_GRADLE_PLUGIN_COMPOSE_VERSION") + ?: "0.1.0-SNAPSHOT" + fun deployVersion(project: Project): String = System.getenv("COMPOSE_GRADLE_PLUGIN_VERSION") ?: composeVersion(project) } diff --git a/gradle-plugins/compose/build.gradle.kts b/gradle-plugins/compose/build.gradle.kts index 2fb7318846..70620ef474 100644 --- a/gradle-plugins/compose/build.gradle.kts +++ b/gradle-plugins/compose/build.gradle.kts @@ -20,7 +20,7 @@ gradlePluginConfig { buildConfig { packageName = "org.jetbrains.compose" clsName = "ComposeBuildConfig" - buildConfigField("String", "composeVersion", BuildProperties.composeVersion) + buildConfigField("String", "composeVersion", BuildProperties.composeVersion(project)) } val embedded by configurations.creating diff --git a/gradle-plugins/gradle.properties b/gradle-plugins/gradle.properties index da5f41f2cb..2273c3c84a 100644 --- a/gradle-plugins/gradle.properties +++ b/gradle-plugins/gradle.properties @@ -1,2 +1,4 @@ org.gradle.parallel=true kotlin.code.style=official + +#compose.version=0.1.0-m1-build57 \ No newline at end of file From 314f5af47f777f0988f3f4de8dc0d399324d0a47 Mon Sep 17 00:00:00 2001 From: Alexey Tsvetkov Date: Tue, 3 Nov 2020 17:13:56 +0300 Subject: [PATCH 6/7] Update all examples with Compose Application DSL --- examples/codeviewer/README.md | 18 +++++++++++---- examples/codeviewer/build.gradle.kts | 4 ++++ examples/codeviewer/desktop/build.gradle.kts | 20 +++++++++++++---- examples/imageviewer/README.md | 16 ++++++++++++-- examples/imageviewer/build.gradle.kts | 1 + examples/issues/README.md | 13 +++++++++-- examples/issues/build.gradle.kts | 2 ++ examples/issues/desktop/build.gradle.kts | 22 ++++++++++++++----- examples/todoapp/README.md | 15 +++++++++++-- examples/todoapp/buildSrc/build.gradle.kts | 4 ++++ examples/todoapp/desktop/build.gradle.kts | 20 +++++++++++++---- templates/desktop-template/README.md | 3 +-- templates/desktop-template/build.gradle.kts | 15 +++++++++---- .../desktop-template/settings.gradle.kts | 2 ++ templates/multiplatform-template/README.md | 3 +-- .../multiplatform-template/build.gradle.kts | 2 ++ .../desktop/build.gradle.kts | 16 +++++++++----- 17 files changed, 140 insertions(+), 36 deletions(-) diff --git a/examples/codeviewer/README.md b/examples/codeviewer/README.md index 364bc6e27a..436a682c77 100644 --- a/examples/codeviewer/README.md +++ b/examples/codeviewer/README.md @@ -1,7 +1,17 @@ MPP Code Viewer example for desktop/android written in Multiplatform Compose library. -To run desktop application execute in a terminal: -`./gradlew desktop:run` +### Running desktop application +``` +./gradlew :desktop:run +``` -To install android application on device/emulator: -'./gradlew installDebug' \ No newline at end of file +### Building native desktop distribution +``` +./gradlew :desktop:package +# outputs are written to desktop/build/compose/binaries +``` + +### Installing Android application on device/emulator +``` +./gradlew installDebug +``` \ No newline at end of file diff --git a/examples/codeviewer/build.gradle.kts b/examples/codeviewer/build.gradle.kts index 5a07e59003..77dc569f53 100644 --- a/examples/codeviewer/build.gradle.kts +++ b/examples/codeviewer/build.gradle.kts @@ -1,5 +1,7 @@ buildscript { repositories { + // TODO: remove after new build is published + mavenLocal() google() jcenter() maven("https://maven.pkg.jetbrains.space/public/p/compose/dev") @@ -16,6 +18,8 @@ buildscript { allprojects { repositories { + // TODO: remove after new build is published + mavenLocal() google() jcenter() maven("https://maven.pkg.jetbrains.space/public/p/compose/dev") diff --git a/examples/codeviewer/desktop/build.gradle.kts b/examples/codeviewer/desktop/build.gradle.kts index 04fb343839..5f86dc5975 100644 --- a/examples/codeviewer/desktop/build.gradle.kts +++ b/examples/codeviewer/desktop/build.gradle.kts @@ -1,10 +1,9 @@ import org.jetbrains.compose.compose +import org.jetbrains.compose.desktop.application.dsl.TargetFormat plugins { kotlin("multiplatform") // kotlin("jvm") doesn't work well in IDEA/AndroidStudio (https://github.com/JetBrains/compose-jb/issues/22) id("org.jetbrains.compose") - java - application } kotlin { @@ -22,6 +21,19 @@ kotlin { } } -application { - mainClassName = "org.jetbrains.codeviewer.MainKt" +compose.desktop { + application { + mainClass = "org.jetbrains.codeviewer.MainKt" + + nativeDistributions { + targetFormats(TargetFormat.Dmg, TargetFormat.Msi, TargetFormat.Deb) + packageName = "ComoseCodeViewer" + + windows { + menu = true + // see https://wixtoolset.org/documentation/manual/v3/howtos/general/generate_guids.html + upgradeUuid = "AF792DA6-2EA3-495A-95E5-C3C6CBCB9948" + } + } + } } diff --git a/examples/imageviewer/README.md b/examples/imageviewer/README.md index 090e0d53ab..c28e88befd 100755 --- a/examples/imageviewer/README.md +++ b/examples/imageviewer/README.md @@ -1,4 +1,16 @@ An example of image gallery for remote server image viewing, based on Jetpack Compose UI library (desktop and android). -To run desktop application execute in terminal: ./gradlew desktop:run -To run android application you will need to open project in Intellij IDEA or Android Studio and run "android" configuration +### Running desktop application +``` +./gradlew :desktop:run +``` + +### Building native desktop distribution +``` +./gradlew :desktop:package +# outputs are written to desktop/build/compose/binaries +``` + +### Running Android application + +Open project in Intellij IDEA or Android Studio and run "android" configuration. diff --git a/examples/imageviewer/build.gradle.kts b/examples/imageviewer/build.gradle.kts index 04d672ff92..727a6a6dab 100755 --- a/examples/imageviewer/build.gradle.kts +++ b/examples/imageviewer/build.gradle.kts @@ -1,5 +1,6 @@ buildscript { repositories { + // TODO: remove after new build is published mavenLocal().mavenContent { includeModule("org.jetbrains.compose", "compose-gradle-plugin") } diff --git a/examples/issues/README.md b/examples/issues/README.md index 20cbaad389..82b13ada5f 100644 --- a/examples/issues/README.md +++ b/examples/issues/README.md @@ -1,4 +1,13 @@ Github Issues viewer example written in Jetpack Compose UI library. -To run desktop application execute in terminal: -`./gradlew run` + +### Running desktop application +``` +./gradlew :desktop:run +``` + +### Building native desktop distribution +``` +./gradlew :desktop:package +# outputs are written to desktop/build/compose/binaries +``` diff --git a/examples/issues/build.gradle.kts b/examples/issues/build.gradle.kts index 55b201313a..6967b0a359 100644 --- a/examples/issues/build.gradle.kts +++ b/examples/issues/build.gradle.kts @@ -1,5 +1,7 @@ buildscript { repositories { + // TODO: remove after new build is published + mavenLocal() google() jcenter() maven("https://maven.pkg.jetbrains.space/public/p/compose/dev") diff --git a/examples/issues/desktop/build.gradle.kts b/examples/issues/desktop/build.gradle.kts index 4a433dfef8..de5b7567be 100644 --- a/examples/issues/desktop/build.gradle.kts +++ b/examples/issues/desktop/build.gradle.kts @@ -1,10 +1,9 @@ import org.jetbrains.compose.compose +import org.jetbrains.compose.desktop.application.dsl.TargetFormat plugins { kotlin("multiplatform") // kotlin("jvm") doesn't work well in IDEA/AndroidStudio (https://github.com/JetBrains/compose-jb/issues/22) id("org.jetbrains.compose") - java - application } kotlin { @@ -21,6 +20,19 @@ kotlin { } } -application { - mainClassName = "androidx.ui.examples.jetissues.MainKt" -} \ No newline at end of file +compose.desktop { + application { + mainClass = "androidx.ui.examples.jetissues.MainKt" + + nativeDistributions { + targetFormats(TargetFormat.Dmg, TargetFormat.Msi, TargetFormat.Deb) + packageName = "IssuesViewer" + + windows { + menu = true + // see https://wixtoolset.org/documentation/manual/v3/howtos/general/generate_guids.html + upgradeUuid = "6565BEAD-713A-4DE7-A469-6B10FC4A6861" + } + } + } +} diff --git a/examples/todoapp/README.md b/examples/todoapp/README.md index 93e6e3124b..a996ce0757 100755 --- a/examples/todoapp/README.md +++ b/examples/todoapp/README.md @@ -23,6 +23,17 @@ Features: - View state is preserved when navigating between screens, Android configuration change, etc. - Model-View-Intent (aka MVI) architectural pattern -To run the desktop application execute the following command: `./gradlew desktop:run`. +### Running desktop application +``` +./gradlew :desktop:run +``` -To run the Android application you will need to open the project in Intellij IDEA or Android Studio and run "android" configuration. +### Building native desktop distribution +``` +./gradlew :desktop:package +# outputs are written to desktop/build/compose/binaries +``` + +### Running Android application + +Open project in Intellij IDEA or Android Studio and run "android" configuration. diff --git a/examples/todoapp/buildSrc/build.gradle.kts b/examples/todoapp/buildSrc/build.gradle.kts index 14902d9219..6fd743b688 100644 --- a/examples/todoapp/buildSrc/build.gradle.kts +++ b/examples/todoapp/buildSrc/build.gradle.kts @@ -4,6 +4,8 @@ plugins { } repositories { + // TODO: remove after new build is published + mavenLocal() google() jcenter() maven("https://maven.pkg.jetbrains.space/public/p/compose/dev") @@ -11,6 +13,8 @@ repositories { buildscript { repositories { + // TODO: remove after new build is published + mavenLocal() google() jcenter() maven("https://maven.pkg.jetbrains.space/public/p/compose/dev") diff --git a/examples/todoapp/desktop/build.gradle.kts b/examples/todoapp/desktop/build.gradle.kts index 0ea31179d7..8d2ebe1944 100755 --- a/examples/todoapp/desktop/build.gradle.kts +++ b/examples/todoapp/desktop/build.gradle.kts @@ -1,10 +1,9 @@ import org.jetbrains.compose.compose +import org.jetbrains.compose.desktop.application.dsl.TargetFormat plugins { kotlin("multiplatform") // kotlin("jvm") doesn't work well in IDEA/AndroidStudio (https://github.com/JetBrains/compose-jb/issues/22) id("org.jetbrains.compose") - java - application } kotlin { @@ -29,6 +28,19 @@ kotlin { } } -application { - mainClassName = "example.todo.desktop.MainKt" +compose.desktop { + application { + mainClass = "example.todo.desktop.MainKt" + + nativeDistributions { + targetFormats(TargetFormat.Dmg, TargetFormat.Msi, TargetFormat.Deb) + packageName = "ComoseDesktopTodo" + + windows { + menuGroup = "Compose Examples" + // see https://wixtoolset.org/documentation/manual/v3/howtos/general/generate_guids.html + upgradeUuid = "BF9CDA6A-1391-46D5-9ED5-383D6E68CCEB" + } + } + } } diff --git a/templates/desktop-template/README.md b/templates/desktop-template/README.md index d47d754f20..fd40023b91 100644 --- a/templates/desktop-template/README.md +++ b/templates/desktop-template/README.md @@ -1,5 +1,4 @@ Compose Desktop Application - `./gradlew run` - run application -- `./gradlew install` - build application into `build/install` -- `./gradlew distZip` - build and create archive ready for distribution in `build/distributions/desktop.zip` \ No newline at end of file +- `./gradlew package` - package native distribution into `build/compose/binaries` diff --git a/templates/desktop-template/build.gradle.kts b/templates/desktop-template/build.gradle.kts index ffd33fec28..3ee01fb050 100644 --- a/templates/desktop-template/build.gradle.kts +++ b/templates/desktop-template/build.gradle.kts @@ -1,9 +1,9 @@ import org.jetbrains.compose.compose +import org.jetbrains.compose.desktop.application.dsl.TargetFormat plugins { kotlin("jvm") version "1.4.0" id("org.jetbrains.compose") version (System.getenv("COMPOSE_TEMPLATE_COMPOSE_VERSION") ?: "0.1.0-m1-build57") - application } repositories { @@ -15,6 +15,13 @@ dependencies { implementation(compose.desktop.currentOs) } -application { - mainClassName = "MainKt" -} +compose.desktop { + application { + mainClass = "MainKt" + + nativeDistributions { + targetFormats(TargetFormat.Dmg, TargetFormat.Msi, TargetFormat.Deb) + packageName = "KotlinJvmComposeDesktopApplication" + } + } +} \ No newline at end of file diff --git a/templates/desktop-template/settings.gradle.kts b/templates/desktop-template/settings.gradle.kts index 781ae9381e..1676142749 100644 --- a/templates/desktop-template/settings.gradle.kts +++ b/templates/desktop-template/settings.gradle.kts @@ -1,5 +1,7 @@ pluginManagement { repositories { + // TODO: remove after new build is published + mavenLocal() gradlePluginPortal() maven("https://maven.pkg.jetbrains.space/public/p/compose/dev") } diff --git a/templates/multiplatform-template/README.md b/templates/multiplatform-template/README.md index 33d19a940e..61bee9df8c 100644 --- a/templates/multiplatform-template/README.md +++ b/templates/multiplatform-template/README.md @@ -2,8 +2,7 @@ Compose Multiplatform Application **Desktop** - `./gradlew run` - run application -- `./gradlew install` - build application into `desktop/build/install` -- `./gradlew distZip` - build and create archive ready for distribution in `desktop/build/distributions/desktop.zip` +- `./gradlew package` - package native distribution into `build/compose/binaries` **Android** - `./gradlew installDebug` - install Android application on an Android device (on a real device or on an emulator) \ No newline at end of file diff --git a/templates/multiplatform-template/build.gradle.kts b/templates/multiplatform-template/build.gradle.kts index 506d7603ed..469fb8fb93 100644 --- a/templates/multiplatform-template/build.gradle.kts +++ b/templates/multiplatform-template/build.gradle.kts @@ -2,6 +2,8 @@ buildscript { val composeVersion = System.getenv("COMPOSE_TEMPLATE_COMPOSE_VERSION") ?: "0.1.0-m1-build57" repositories { + // TODO: remove after new build is published + mavenLocal() google() jcenter() maven("https://maven.pkg.jetbrains.space/public/p/compose/dev") diff --git a/templates/multiplatform-template/desktop/build.gradle.kts b/templates/multiplatform-template/desktop/build.gradle.kts index eaa9f9e584..f430a77e8d 100644 --- a/templates/multiplatform-template/desktop/build.gradle.kts +++ b/templates/multiplatform-template/desktop/build.gradle.kts @@ -1,10 +1,9 @@ import org.jetbrains.compose.compose +import org.jetbrains.compose.desktop.application.dsl.TargetFormat plugins { kotlin("multiplatform") // kotlin("jvm") doesn't work well in IDEA/AndroidStudio (https://github.com/JetBrains/compose-jb/issues/22) id("org.jetbrains.compose") - java - application } kotlin { @@ -21,6 +20,13 @@ kotlin { } } -application { - mainClassName = "MainKt" -} +compose.desktop { + application { + mainClass = "MainKt" + + nativeDistributions { + targetFormats(TargetFormat.Dmg, TargetFormat.Msi, TargetFormat.Deb) + packageName = "KotlinMultiplatformComposeDesktopApplication" + } + } +} \ No newline at end of file From 3799ca1f16cc58f471c31ccdee2909e1d4fe4513 Mon Sep 17 00:00:00 2001 From: Igor Demin Date: Tue, 3 Nov 2020 22:49:57 +0300 Subject: [PATCH 7/7] Fix typos --- examples/codeviewer/desktop/build.gradle.kts | 2 +- examples/imageviewer/README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/codeviewer/desktop/build.gradle.kts b/examples/codeviewer/desktop/build.gradle.kts index 5f86dc5975..62e6c79bef 100644 --- a/examples/codeviewer/desktop/build.gradle.kts +++ b/examples/codeviewer/desktop/build.gradle.kts @@ -27,7 +27,7 @@ compose.desktop { nativeDistributions { targetFormats(TargetFormat.Dmg, TargetFormat.Msi, TargetFormat.Deb) - packageName = "ComoseCodeViewer" + packageName = "ComposeCodeViewer" windows { menu = true diff --git a/examples/imageviewer/README.md b/examples/imageviewer/README.md index c28e88befd..1b0667682a 100755 --- a/examples/imageviewer/README.md +++ b/examples/imageviewer/README.md @@ -13,4 +13,4 @@ An example of image gallery for remote server image viewing, based on Jetpack Co ### Running Android application -Open project in Intellij IDEA or Android Studio and run "android" configuration. +Open project in IntelliJ IDEA or Android Studio and run "android" configuration.