From 9e3a99197be5ca4e181021b3e1f0702176ba1e1e Mon Sep 17 00:00:00 2001 From: FunkyMuse Date: Mon, 22 Jan 2024 14:25:55 +0100 Subject: [PATCH] fix: configure publishing --- .../kotlin/KotlinLibraryConventionPlugin.kt | 1 - .../main/kotlin/LibraryConventionPlugin.kt | 1 - build.gradle.kts | 37 ++++++++++++++++++- 3 files changed, 36 insertions(+), 3 deletions(-) diff --git a/build-logic/convention/src/main/kotlin/KotlinLibraryConventionPlugin.kt b/build-logic/convention/src/main/kotlin/KotlinLibraryConventionPlugin.kt index c76266282..911d923b2 100644 --- a/build-logic/convention/src/main/kotlin/KotlinLibraryConventionPlugin.kt +++ b/build-logic/convention/src/main/kotlin/KotlinLibraryConventionPlugin.kt @@ -13,7 +13,6 @@ class KotlinLibraryConventionPlugin : Plugin { apply(versionCatalog.getPluginId("java-library")) apply(versionCatalog.getPluginId("kotlinJvm")) apply(versionCatalog.getPluginId("dokka")) - apply(versionCatalog.getVersion("gradlePlugins-maven-publish")) } configureJava { toolchain { diff --git a/build-logic/convention/src/main/kotlin/LibraryConventionPlugin.kt b/build-logic/convention/src/main/kotlin/LibraryConventionPlugin.kt index de70784b4..8ceda6224 100644 --- a/build-logic/convention/src/main/kotlin/LibraryConventionPlugin.kt +++ b/build-logic/convention/src/main/kotlin/LibraryConventionPlugin.kt @@ -20,7 +20,6 @@ class LibraryConventionPlugin : Plugin { apply(versionCatalog.getPluginId("kotlinAndroid")) apply(versionCatalog.getPluginId("spotless")) apply(versionCatalog.getPluginId("dokka")) - apply(versionCatalog.getVersion("gradlePlugins-maven-publish")) } configureKotlinOptions() configureLibraryAndTestNameSpace() diff --git a/build.gradle.kts b/build.gradle.kts index 392868056..a8b69a75d 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,6 +1,8 @@ import com.diffplug.gradle.spotless.SpotlessPlugin +import com.android.build.gradle.LibraryPlugin plugins { + id(libs.versions.gradlePlugins.maven.publish.get()) alias(libs.plugins.android).apply(false) alias(libs.plugins.library).apply(false) alias(libs.plugins.kotlinAndroid).apply(false) @@ -63,4 +65,37 @@ allprojects { } } } -} \ No newline at end of file +} + +subprojects { + plugins.matching { anyPlugin -> supportedPlugins(anyPlugin) }.whenPluginAdded { + apply(plugin = libs.versions.gradlePlugins.maven.publish.get()) + plugins.withType { + publishing.publications { + create("kotlin") { + artifactId = this@subprojects.name + version = libs.versions.app.version.versionName.get() + afterEvaluate { + from(components["kotlin"]) + } + } + } + } + plugins.withType { + afterEvaluate { + publishing.publications { + create("release") { + artifactId = this@subprojects.name + version = libs.versions.app.version.versionName.get() + afterEvaluate { + from(components["release"]) + } + } + } + } + } + } +} + +fun supportedPlugins(anyPlugin: Plugin<*>?) = + anyPlugin is LibraryPlugin || anyPlugin is JavaLibraryPlugin \ No newline at end of file