diff --git a/version-catalog-extensions/src/main/kotlin/ValidateVersionCatalogTask.kt b/version-catalog-extensions/src/main/kotlin/ValidateVersionCatalogTask.kt index 8c86c89..d885158 100644 --- a/version-catalog-extensions/src/main/kotlin/ValidateVersionCatalogTask.kt +++ b/version-catalog-extensions/src/main/kotlin/ValidateVersionCatalogTask.kt @@ -10,12 +10,18 @@ import org.gradle.api.provider.Property import org.gradle.api.tasks.Input import org.gradle.api.tasks.TaskAction import org.gradle.kotlin.dsl.named +import org.gradle.language.base.plugins.LifecycleBasePlugin abstract class ValidateVersionCatalogTask : DefaultTask() { @get:Input abstract val dependenciesModel: Property + init { + group = LifecycleBasePlugin.VERIFICATION_GROUP + description = "Validates version catalog" + } + @TaskAction fun validate() { val catalog = dependenciesModel.get() @@ -23,10 +29,10 @@ abstract class ValidateVersionCatalogTask : DefaultTask() { // Check libraries in catalog are resolvable val configuration = createConfiguration() configuration.addLibraries(catalog) - println("Resolved dependencies:") + logger.debug("Resolved dependencies:") configuration.resolvedConfiguration .firstLevelModuleDependencies - .forEach { println("- ${it.name}") } + .forEach { logger.debug("- ${it.name}") } catalog.checkVersionsUsed() } diff --git a/version-catalog-extensions/src/main/kotlin/VersionCatalogExtensionsPlugin.kt b/version-catalog-extensions/src/main/kotlin/VersionCatalogExtensionsPlugin.kt index 94a9a6e..661081f 100644 --- a/version-catalog-extensions/src/main/kotlin/VersionCatalogExtensionsPlugin.kt +++ b/version-catalog-extensions/src/main/kotlin/VersionCatalogExtensionsPlugin.kt @@ -2,16 +2,24 @@ package com.redmadrobot.gradle.catalog import org.gradle.api.Plugin import org.gradle.api.Project +import org.gradle.api.plugins.catalog.VersionCatalogPlugin.GENERATE_CATALOG_FILE_TASKNAME import org.gradle.api.plugins.catalog.internal.CatalogExtensionInternal import org.gradle.kotlin.dsl.getByName import org.gradle.kotlin.dsl.register +import org.gradle.language.base.plugins.LifecycleBasePlugin.CHECK_TASK_NAME class VersionCatalogExtensionsPlugin : Plugin { - override fun apply(target: Project) { - val extension = target.extensions.getByName("catalog") - target.tasks.register("validateCatalog") { + override fun apply(target: Project) = with(target) { + val extension = extensions.getByName("catalog") + val validateCatalog = tasks.register(VALIDATE_CATALOG_TASK_NAME) { dependenciesModel.set(extension.versionCatalog) + dependsOn(tasks.named(GENERATE_CATALOG_FILE_TASKNAME)) } + tasks.named(CHECK_TASK_NAME).configure { dependsOn(validateCatalog) } + } + + companion object { + const val VALIDATE_CATALOG_TASK_NAME = "validateCatalog" } }