From 3aa8b83b4191f972ffae1131e6cfc60fddacc288 Mon Sep 17 00:00:00 2001 From: James Bradlee Date: Mon, 1 Apr 2024 12:37:44 +0200 Subject: [PATCH 1/3] build: added isEnabled on publishing extension (#22) --- .../kotlin/io/tnboot/gradle/build/PublishPlugin.kt | 10 +++++++--- telenor-boot-dependencies/build.gradle.kts | 8 ++++++++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/buildSrc/src/main/kotlin/io/tnboot/gradle/build/PublishPlugin.kt b/buildSrc/src/main/kotlin/io/tnboot/gradle/build/PublishPlugin.kt index 02a4a60..7e8112d 100644 --- a/buildSrc/src/main/kotlin/io/tnboot/gradle/build/PublishPlugin.kt +++ b/buildSrc/src/main/kotlin/io/tnboot/gradle/build/PublishPlugin.kt @@ -20,7 +20,9 @@ class PublishPlugin : Plugin { } } - open class Extension { + open class Extension( + private val project: Project, + ) { var enabled = true var evenWithChildren = false @@ -37,13 +39,15 @@ class PublishPlugin : Plugin { fun configure(block: MavenPublication.() -> Unit) { configurations.add(block) } + + val isEnabled get() = enabled && (evenWithChildren || project.childProjects.isEmpty()) } override fun apply(target: Project) { - target.extensions.add(Extension::class.java, "publish", Extension()) + target.extensions.add(Extension::class.java, "publish", Extension(target)) target.afterEvaluate { target.extensions.getByType(Extension::class.java).let { extension -> - if (!extension.enabled || (target.childProjects.isNotEmpty() && !extension.evenWithChildren)) return@afterEvaluate + if (!extension.isEnabled) return@afterEvaluate log.debug("Enabling Maven Publications for project {}", target.name) target.mavenPublish { extension.configurations.forEach { diff --git a/telenor-boot-dependencies/build.gradle.kts b/telenor-boot-dependencies/build.gradle.kts index 00e12aa..6eba309 100644 --- a/telenor-boot-dependencies/build.gradle.kts +++ b/telenor-boot-dependencies/build.gradle.kts @@ -1,4 +1,5 @@ import io.tnboot.gradle.build.DependencyGroups +import io.tnboot.gradle.build.PublishPlugin import io.tnboot.gradle.build.mavenPublish plugins { @@ -15,6 +16,13 @@ val bom = DependencyGroups( dependencies { constraints { bom.dependencies.forEach { add("api", it) } + + rootProject.allprojects.filter { + it != project && it.plugins.hasPlugin(PublishPlugin::class.java) && + it.extensions.getByType(PublishPlugin.Extension::class.java).isEnabled + }.forEach { + add("api", it) + } } } From c2ec41714d64f803da05fe3803c78c5c6ad32fbd Mon Sep 17 00:00:00 2001 From: James Bradlee Date: Mon, 1 Apr 2024 12:41:32 +0200 Subject: [PATCH 2/3] fix: rename mavenPublish.kt to MavenPublish.kt in accordance with KtLint (#23) --- .../io/tnboot/gradle/build/{mavenPublish.kt => MavenPublish.kt} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename buildSrc/src/main/kotlin/io/tnboot/gradle/build/{mavenPublish.kt => MavenPublish.kt} (100%) diff --git a/buildSrc/src/main/kotlin/io/tnboot/gradle/build/mavenPublish.kt b/buildSrc/src/main/kotlin/io/tnboot/gradle/build/MavenPublish.kt similarity index 100% rename from buildSrc/src/main/kotlin/io/tnboot/gradle/build/mavenPublish.kt rename to buildSrc/src/main/kotlin/io/tnboot/gradle/build/MavenPublish.kt From 8c4593438831f5fa32c50099f4e79d9926a65e2a Mon Sep 17 00:00:00 2001 From: James Bradlee Date: Mon, 1 Apr 2024 13:00:20 +0200 Subject: [PATCH 3/3] build: made indexing all published modules cleaner (#24) --- .../kotlin/io/tnboot/gradle/build/PublishPlugin.kt | 4 ++-- .../gradle/build/{MavenPublish.kt => PublishUtil.kt} | 7 +++++++ telenor-boot-dependencies/build.gradle.kts | 11 +++-------- 3 files changed, 12 insertions(+), 10 deletions(-) rename buildSrc/src/main/kotlin/io/tnboot/gradle/build/{MavenPublish.kt => PublishUtil.kt} (81%) diff --git a/buildSrc/src/main/kotlin/io/tnboot/gradle/build/PublishPlugin.kt b/buildSrc/src/main/kotlin/io/tnboot/gradle/build/PublishPlugin.kt index 7e8112d..fbc585c 100644 --- a/buildSrc/src/main/kotlin/io/tnboot/gradle/build/PublishPlugin.kt +++ b/buildSrc/src/main/kotlin/io/tnboot/gradle/build/PublishPlugin.kt @@ -40,14 +40,14 @@ class PublishPlugin : Plugin { configurations.add(block) } - val isEnabled get() = enabled && (evenWithChildren || project.childProjects.isEmpty()) + val isPublished get() = enabled && (evenWithChildren || project.childProjects.isEmpty()) } override fun apply(target: Project) { target.extensions.add(Extension::class.java, "publish", Extension(target)) target.afterEvaluate { target.extensions.getByType(Extension::class.java).let { extension -> - if (!extension.isEnabled) return@afterEvaluate + if (!extension.isPublished) return@afterEvaluate log.debug("Enabling Maven Publications for project {}", target.name) target.mavenPublish { extension.configurations.forEach { diff --git a/buildSrc/src/main/kotlin/io/tnboot/gradle/build/MavenPublish.kt b/buildSrc/src/main/kotlin/io/tnboot/gradle/build/PublishUtil.kt similarity index 81% rename from buildSrc/src/main/kotlin/io/tnboot/gradle/build/MavenPublish.kt rename to buildSrc/src/main/kotlin/io/tnboot/gradle/build/PublishUtil.kt index 2110d71..0b93e6a 100644 --- a/buildSrc/src/main/kotlin/io/tnboot/gradle/build/MavenPublish.kt +++ b/buildSrc/src/main/kotlin/io/tnboot/gradle/build/PublishUtil.kt @@ -32,3 +32,10 @@ fun Project.mavenPublish(block: MavenPublication.() -> Unit) { } } } + +val Project.publishedProjects get() = rootProject.allprojects.filter { + it != project && it.plugins.hasPlugin(PublishPlugin::class.java) && + it.extensions.getByType(PublishPlugin.Extension::class.java).isPublished +} + +val Project.notation get() = "$group:$name:$version" diff --git a/telenor-boot-dependencies/build.gradle.kts b/telenor-boot-dependencies/build.gradle.kts index 6eba309..9b0639d 100644 --- a/telenor-boot-dependencies/build.gradle.kts +++ b/telenor-boot-dependencies/build.gradle.kts @@ -1,6 +1,7 @@ import io.tnboot.gradle.build.DependencyGroups -import io.tnboot.gradle.build.PublishPlugin import io.tnboot.gradle.build.mavenPublish +import io.tnboot.gradle.build.notation +import io.tnboot.gradle.build.publishedProjects plugins { `java-platform` @@ -16,13 +17,7 @@ val bom = DependencyGroups( dependencies { constraints { bom.dependencies.forEach { add("api", it) } - - rootProject.allprojects.filter { - it != project && it.plugins.hasPlugin(PublishPlugin::class.java) && - it.extensions.getByType(PublishPlugin.Extension::class.java).isEnabled - }.forEach { - add("api", it) - } + publishedProjects.forEach { add("api", it.notation) } } }