Skip to content

Commit

Permalink
Use task name/group constants
Browse files Browse the repository at this point in the history
  • Loading branch information
Virtlink committed Jul 22, 2024
1 parent 2824fc8 commit a7ab30a
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 28 deletions.
Original file line number Diff line number Diff line change
@@ -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. */
Expand All @@ -15,25 +18,25 @@ open class RootProjectConventionExtension @Inject constructor(

/** The name of the `assemble` task. */
val assembleTaskName: Property<String> = 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<String> = 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<String> = 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<String> = 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<String> = 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<String> = 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<String> = 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<String> = objects.property(String::class.java)
.convention("allTasks")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -25,50 +28,50 @@ class RootProjectConventionPlugin: Plugin<Project> {
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
Expand Down

0 comments on commit a7ab30a

Please sign in to comment.