Browse Source
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.pull/45/head
Alexey Tsvetkov
4 years ago
23 changed files with 87 additions and 117 deletions
@ -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>("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>("jar") { |
|
||||||
dependsOn(shadow) |
|
||||||
from(zipTree(shadow.get().archiveFile)) |
|
||||||
this.duplicatesStrategy = DuplicatesStrategy.INCLUDE |
|
||||||
} |
|
@ -1,10 +0,0 @@ |
|||||||
package org.jetbrains.compose |
|
||||||
|
|
||||||
import org.gradle.api.Plugin |
|
||||||
import org.gradle.api.Project |
|
||||||
|
|
||||||
open class ComposeBasePlugin : Plugin<Project> { |
|
||||||
override fun apply(project: Project) { |
|
||||||
project.extensions.create("compose", ComposeExtension::class.java) |
|
||||||
} |
|
||||||
} |
|
@ -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<Project> { |
|
||||||
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) |
|
||||||
} |
|
||||||
} |
|
@ -1,5 +0,0 @@ |
|||||||
package org.jetbrains.compose.desktop |
|
||||||
|
|
||||||
import org.gradle.api.plugins.ExtensionAware |
|
||||||
|
|
||||||
abstract class DesktopExtension : ExtensionAware |
|
@ -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() |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue