Refactor gradle-plugin build configuration to allow other plugins

So other plugins can be added to separate subprojects
This commit is contained in:
Alexey Tsvetkov
2020-10-20 10:31:39 +03:00
committed by Alexey Tsvetkov
parent 09083131ff
commit a8e34eddad
20 changed files with 170 additions and 102 deletions

View File

@@ -12,6 +12,6 @@ at https://android.googlesource.com/platform/frameworks/support.
* `examples` - examples of multiplatform Compose applications for Desktop and Android
* `imageviewer` - Image Viewer application for Android and Desktop
* `issues` - GitHub issue tracker with an adaptive UI and ktor-client
* `gradle-plugin` - plugin for simpler usage of Compose with Gradle build
* `gradle-plugins` - plugins, simplifying usage of Compose with Gradle
* `templates` - new application templates (see `desktop-template/build_and_run_from_cli_example.sh` for using without Gradle)
* `tutorials` - tutorials on using Compose for Desktop

View File

@@ -1,7 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
</component>
</project>

View File

@@ -1,5 +0,0 @@
Jetpack Compose gradle plugin for easy configuration
Environment variables:
COMPOSE_GRADLE_PLUGIN_VERSION - version of plugin
COMPOSE_GRADLE_PLUGIN_COMPOSE_VERSION - version of Jetpack Compose which will be used when the plugin is applied

View File

@@ -1,88 +0,0 @@
plugins {
kotlin("jvm") version "1.4.0"
id("com.gradle.plugin-publish") version "0.10.1"
id("de.fuerstenau.buildconfig") version "1.1.8"
id("java-gradle-plugin")
id("maven-publish")
}
private object Info {
const val name = "Jetpack Compose Plugin"
const val website = "https://jetbrains.org/compose"
const val description = "Jetpack Compose gradle plugin for easy configuration"
const val artifactId = "compose-gradle-plugin"
val composeVersion = System.getenv("COMPOSE_GRADLE_PLUGIN_COMPOSE_VERSION") ?: "0.1.0-SNAPSHOT"
val version = System.getenv("COMPOSE_GRADLE_PLUGIN_VERSION") ?: composeVersion
}
group = "org.jetbrains.compose"
version = Info.version
java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
repositories {
maven("https://dl.bintray.com/kotlin/kotlin-dev")
jcenter()
mavenLocal()
}
dependencies {
implementation(gradleApi())
implementation(localGroovy())
compileOnly("org.jetbrains.kotlin:kotlin-gradle-plugin")
testImplementation(gradleTestKit())
}
buildConfig {
packageName = "org.jetbrains.compose"
clsName = "ComposeBuildConfig"
buildConfigField("String", "composeVersion", Info.composeVersion)
}
gradlePlugin {
plugins {
create("compose") {
id = "org.jetbrains.compose"
displayName = Info.name
description = Info.description
implementationClass = "org.jetbrains.compose.ComposePlugin"
version = project.version
}
}
}
pluginBundle {
website = Info.website
description = Info.description
}
publishing {
repositories {
maven {
setUrl(System.getenv("COMPOSE_REPO_URL"))
credentials {
username = System.getenv("COMPOSE_REPO_USERNAME")
password = System.getenv("COMPOSE_REPO_KEY")
}
}
}
publications {
create<MavenPublication>("pluginMaven") {
artifactId = Info.artifactId
pom {
name.set(Info.name)
description.set(Info.description)
url.set(Info.website)
licenses {
license {
name.set("The Apache License, Version 2.0")
url.set("http://www.apache.org/licenses/LICENSE-2.0.txt")
}
}
}
}
}
}

5
gradle-plugins/README.md Normal file
View File

@@ -0,0 +1,5 @@
Jetpack Compose gradle plugin for easy configuration
Environment variables:
* `COMPOSE_GRADLE_PLUGIN_VERSION` - version of plugin
* `COMPOSE_GRADLE_PLUGIN_COMPOSE_VERSION` - version of Jetpack Compose used by the plugin

View File

@@ -0,0 +1,83 @@
import com.gradle.publish.PluginBundleExtension
plugins {
kotlin("jvm") version "1.4.0" apply false
id("com.gradle.plugin-publish") version "0.10.1" apply false
id("de.fuerstenau.buildconfig") version "1.1.8" apply false
}
subprojects {
group = BuildProperties.group
version = BuildProperties.version
repositories {
maven("https://dl.bintray.com/kotlin/kotlin-dev")
jcenter()
mavenLocal()
}
plugins.withId("java") {
configureIfExists<JavaPluginExtension> {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
}
plugins.withId("maven-publish") {
configureIfExists<PublishingExtension> {
repositories {
maven("ComposeRepo") {
setUrl(System.getenv("COMPOSE_REPO_URL"))
credentials {
username = System.getenv("COMPOSE_REPO_USERNAME")
password = System.getenv("COMPOSE_REPO_KEY")
}
}
}
}
}
afterEvaluate {
gradlePluginConfig?.let { configureGradlePlugin(it) }
}
}
fun Project.configureGradlePlugin(config: GradlePluginConfigExtension) {
// maven publication for plugin
configureIfExists<PublishingExtension> {
publications.create<MavenPublication>("gradlePlugin") {
artifactId = config.artifactId
pom {
name.set(config.displayName)
description.set(config.description)
url.set(BuildProperties.website)
licenses {
license {
name.set("The Apache License, Version 2.0")
url.set("http://www.apache.org/licenses/LICENSE-2.0.txt")
}
}
}
}
}
// metadata for gradle plugin portal (relates to pluginBundle extension block from com.gradle.plugin-publish)
configureIfExists<PluginBundleExtension> {
vcsUrl = BuildProperties.vcs
website = BuildProperties.website
description = config.description
}
// gradle plugin definition (relates to gradlePlugin extension block from java-gradle-plugin)
configureIfExists<GradlePluginDevelopmentExtension> {
plugins {
create("gradlePlugin") {
id = config.pluginId
displayName = config.displayName
description = config.description
implementationClass = config.implementationClass
version = project.version
}
}
}
}

View File

@@ -0,0 +1,12 @@
plugins {
`kotlin-dsl`
}
repositories {
gradlePluginPortal()
}
dependencies {
compileOnly(gradleApi())
implementation(kotlin("stdlib"))
}

View File

@@ -0,0 +1,5 @@
pluginManagement {
repositories {
gradlePluginPortal()
}
}

View File

@@ -0,0 +1,11 @@
// "Global" properties
object BuildProperties {
const val name = "Jetpack 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
}

View File

@@ -0,0 +1,17 @@
import org.gradle.api.Project
// Plugin-specific properties (also see gradle-plugins/build.gradle.kts)
open class GradlePluginConfigExtension {
lateinit var pluginId: String
lateinit var artifactId: String
lateinit var implementationClass: String
lateinit var displayName: String
lateinit var description: String
}
val Project.gradlePluginConfig: GradlePluginConfigExtension?
get() = extensions.findByType(GradlePluginConfigExtension::class.java)
fun Project.gradlePluginConfig(fn: GradlePluginConfigExtension.() -> Unit) {
extensions.create("gradlePluginConfig", GradlePluginConfigExtension::class.java).apply(fn)
}

View File

@@ -0,0 +1,5 @@
import org.gradle.api.Project
inline fun <reified T> Project.configureIfExists(fn: T.() -> Unit) {
extensions.findByType(T::class.java)?.fn()
}

View File

@@ -0,0 +1,28 @@
plugins {
kotlin("jvm")
id("de.fuerstenau.buildconfig")
id("com.gradle.plugin-publish")
id("java-gradle-plugin")
id("maven-publish")
}
gradlePluginConfig {
pluginId = "org.jetbrains.compose"
artifactId = "compose-gradle-plugin"
displayName = "Jetpack Compose Plugin"
description = "Jetpack Compose gradle plugin for easy configuration"
implementationClass = "org.jetbrains.compose.ComposePlugin"
}
buildConfig {
packageName = "org.jetbrains.compose"
clsName = "ComposeBuildConfig"
buildConfigField("String", "composeVersion", BuildProperties.composeVersion)
}
dependencies {
compileOnly(gradleApi())
compileOnly(localGroovy())
compileOnly("org.jetbrains.kotlin:kotlin-gradle-plugin")
testImplementation(gradleTestKit())
}

View File

@@ -3,4 +3,6 @@ pluginManagement {
gradlePluginPortal()
maven("https://dl.bintray.com/kotlin/kotlin-dev")
}
}
}
include(":compose")