From a7ab30aecf62e696cc1937a4ebfe08204e8f1d81 Mon Sep 17 00:00:00 2001 From: "Daniel A. A. Pelsmaeker" Date: Mon, 22 Jul 2024 14:37:29 +0200 Subject: [PATCH] Use task name/group constants --- .../RootProjectConventionExtension.kt | 17 ++++--- .../convention/RootProjectConventionPlugin.kt | 45 ++++++++++--------- 2 files changed, 34 insertions(+), 28 deletions(-) diff --git a/convention-plugin/src/main/kotlin/org/metaborg/convention/RootProjectConventionExtension.kt b/convention-plugin/src/main/kotlin/org/metaborg/convention/RootProjectConventionExtension.kt index 5ba2c3e..41b3908 100644 --- a/convention-plugin/src/main/kotlin/org/metaborg/convention/RootProjectConventionExtension.kt +++ b/convention-plugin/src/main/kotlin/org/metaborg/convention/RootProjectConventionExtension.kt @@ -1,7 +1,10 @@ package org.metaborg.convention import org.gradle.api.model.ObjectFactory +import org.gradle.api.plugins.JavaPlugin import org.gradle.api.provider.Property +import org.gradle.api.publish.plugins.PublishingPlugin +import org.gradle.language.base.plugins.LifecycleBasePlugin import javax.inject.Inject /** Configuration for the root project convention. */ @@ -15,25 +18,25 @@ open class RootProjectConventionExtension @Inject constructor( /** The name of the `assemble` task. */ val assembleTaskName: Property = objects.property(String::class.java) - .convention(taskNameSuffix.map { "assemble$it"} ) + .convention(taskNameSuffix.map { "${LifecycleBasePlugin.ASSEMBLE_TASK_NAME}$it"} ) /** The name of the `build` task. */ val buildTaskName: Property = objects.property(String::class.java) - .convention(taskNameSuffix.map { "build$it"} ) + .convention(taskNameSuffix.map { "${LifecycleBasePlugin.BUILD_TASK_NAME}$it"} ) /** The name of the `clean` task. */ val cleanTaskName: Property = objects.property(String::class.java) - .convention(taskNameSuffix.map { "clean$it"} ) + .convention(taskNameSuffix.map { "${LifecycleBasePlugin.CLEAN_TASK_NAME}$it"} ) /** The name of the `publish` task. */ val publishTaskName: Property = objects.property(String::class.java) - .convention(taskNameSuffix.map { "publish$it"} ) + .convention(taskNameSuffix.map { "${PublishingPlugin.PUBLISH_LIFECYCLE_TASK_NAME}$it"} ) /** The name of the `publishToMavenLocal` task. */ val publishToMavenLocalTaskName: Property = objects.property(String::class.java) - .convention(taskNameSuffix.map { "publish${it}ToMavenLocal"} ) + .convention(taskNameSuffix.map { "${PublishingPlugin.PUBLISH_LIFECYCLE_TASK_NAME}${it}ToMavenLocal"} ) /** The name of the `check` task. */ val checkTaskName: Property = objects.property(String::class.java) - .convention(taskNameSuffix.map { "check$it"} ) + .convention(taskNameSuffix.map { "${LifecycleBasePlugin.CHECK_TASK_NAME}$it"} ) /** The name of the `test` task. */ val testTaskName: Property = objects.property(String::class.java) - .convention(taskNameSuffix.map { "test$it"} ) + .convention(taskNameSuffix.map { "${JavaPlugin.TEST_TASK_NAME}$it"} ) /** The name of the `tasks` task. */ val tasksTaskName: Property = objects.property(String::class.java) .convention("allTasks") diff --git a/convention-plugin/src/main/kotlin/org/metaborg/convention/RootProjectConventionPlugin.kt b/convention-plugin/src/main/kotlin/org/metaborg/convention/RootProjectConventionPlugin.kt index 6c6360d..19e4302 100644 --- a/convention-plugin/src/main/kotlin/org/metaborg/convention/RootProjectConventionPlugin.kt +++ b/convention-plugin/src/main/kotlin/org/metaborg/convention/RootProjectConventionPlugin.kt @@ -2,7 +2,10 @@ package org.metaborg.convention import org.gradle.api.Plugin import org.gradle.api.Project +import org.gradle.api.plugins.JavaPlugin +import org.gradle.api.publish.plugins.PublishingPlugin import org.gradle.kotlin.dsl.create +import org.gradle.language.base.plugins.LifecycleBasePlugin /** * Configures a root project of a multi-project build, by adding explicit tasks @@ -25,50 +28,50 @@ class RootProjectConventionPlugin: Plugin { afterEvaluate { // Build tasks tasks.register(extension.assembleTaskName.get()) { - group = "Build" + group = LifecycleBasePlugin.BUILD_GROUP description = "Assembles the outputs of the subprojects and included builds." - dependsOn(gradle.includedBuilds.map { it.task(":assemble") }) - dependsOn(project.subprojects.mapNotNull { it.tasks.findByName("assemble") }) + dependsOn(gradle.includedBuilds.map { it.task(":${LifecycleBasePlugin.ASSEMBLE_TASK_NAME}") }) + dependsOn(project.subprojects.mapNotNull { it.tasks.findByName(LifecycleBasePlugin.ASSEMBLE_TASK_NAME) }) } tasks.register(extension.buildTaskName.get()) { - group = "Build" + group = LifecycleBasePlugin.BUILD_GROUP description = "Assembles and tests the subprojects and included builds." - dependsOn(gradle.includedBuilds.map { it.task(":build") }) - dependsOn(project.subprojects.mapNotNull { it.tasks.findByName("build") }) + dependsOn(gradle.includedBuilds.map { it.task(":${LifecycleBasePlugin.BUILD_TASK_NAME}") }) + dependsOn(project.subprojects.mapNotNull { it.tasks.findByName(LifecycleBasePlugin.BUILD_TASK_NAME) }) } tasks.register(extension.cleanTaskName.get()) { - group = "Build" + group = LifecycleBasePlugin.BUILD_GROUP description = "Cleans the outputs of the subprojects and included builds." - dependsOn(gradle.includedBuilds.map { it.task(":clean") }) - dependsOn(project.subprojects.mapNotNull { it.tasks.findByName("clean") }) + dependsOn(gradle.includedBuilds.map { it.task(":${LifecycleBasePlugin.CLEAN_TASK_NAME}") }) + dependsOn(project.subprojects.mapNotNull { it.tasks.findByName(LifecycleBasePlugin.CLEAN_TASK_NAME) }) } // Publishing tasks tasks.register(extension.publishTaskName.get()) { - group = "Publishing" + group = PublishingPlugin.PUBLISH_TASK_GROUP description = "Publishes all subprojects and included builds to a remote Maven repository." - dependsOn(gradle.includedBuilds.map { it.task(":publish") }) - dependsOn(project.subprojects.mapNotNull { it.tasks.findByName("publish") }) + dependsOn(gradle.includedBuilds.map { it.task(":${PublishingPlugin.PUBLISH_LIFECYCLE_TASK_NAME}") }) + dependsOn(project.subprojects.mapNotNull { it.tasks.findByName(PublishingPlugin.PUBLISH_LIFECYCLE_TASK_NAME) }) } tasks.register(extension.publishToMavenLocalTaskName.get()) { - group = "Publishing" + group = PublishingPlugin.PUBLISH_TASK_GROUP description = "Publishes all subprojects and included builds to the local Maven repository." - dependsOn(gradle.includedBuilds.map { it.task(":publishToMavenLocal") }) - dependsOn(project.subprojects.mapNotNull { it.tasks.findByName("publishToMavenLocal") }) + dependsOn(gradle.includedBuilds.map { it.task(":${PublishingPlugin.PUBLISH_LIFECYCLE_TASK_NAME}ToMavenLocal") }) + dependsOn(project.subprojects.mapNotNull { it.tasks.findByName("${PublishingPlugin.PUBLISH_LIFECYCLE_TASK_NAME}ToMavenLocal") }) } // Verification tasks tasks.register(extension.checkTaskName.get()) { - group = "Verification" + group = LifecycleBasePlugin.VERIFICATION_GROUP description = "Runs all checks on the subprojects and included builds." - dependsOn(gradle.includedBuilds.map { it.task(":check") }) - dependsOn(project.subprojects.mapNotNull { it.tasks.findByName("check") }) + dependsOn(gradle.includedBuilds.map { it.task(":${LifecycleBasePlugin.CHECK_TASK_NAME}") }) + dependsOn(project.subprojects.mapNotNull { it.tasks.findByName(LifecycleBasePlugin.CHECK_TASK_NAME) }) } tasks.register(extension.testTaskName.get()) { - group = "Verification" + group = LifecycleBasePlugin.VERIFICATION_GROUP description = "Runs all unit tests on the subprojects and included builds." - dependsOn(gradle.includedBuilds.map { it.task(":test") }) - dependsOn(project.subprojects.mapNotNull { it.tasks.findByName("test") }) + dependsOn(gradle.includedBuilds.map { it.task(":${JavaPlugin.TEST_TASK_NAME}") }) + dependsOn(project.subprojects.mapNotNull { it.tasks.findByName(JavaPlugin.TEST_TASK_NAME) }) } // Help tasks