All Downloads are FREE. Search and download functionalities are using the official Maven repository.

gradle-plugins.projects-version-catalog.0.1.0-rc.31.source-code.ProjectsVersionCatalogPlugin.kt Maven / Gradle / Ivy

There is a newer version: 0.1.0-rc.45
Show newest version
package com.javiersc.gradle.plugins.projects.version.catalog

import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.kotlin.dsl.register

abstract class ProjectsVersionCatalogPlugin : Plugin {

    override fun apply(project: Project) {
        project.createProjectsVersionCatalogExtension()

        val extension = project.projectsVersionCatalogExtension

        project.configureProjectsVersionCatalogExtension()

        val buildVersionCatalogTask =
            project.tasks.register(BuildVersionCatalogTask.name) {
                librariesPrefix = extension.librariesPrefix.get()
                projects = extension.projects.get()
                removeVersionAliasPrefix = extension.removeVersionAliasPrefix.get()
                tomlPath = extension.tomlPath.get()
            }

        val warningMessage = "Run `${BuildVersionCatalogTask.name}` to generate the Version Catalog"
        val generateCatalogAsTomlTask = project.tasks.findByName("generateCatalogAsToml")
        val assembleTask = project.tasks.findByName("assemble")

        when {
            generateCatalogAsTomlTask != null -> {
                generateCatalogAsTomlTask.dependsOn(buildVersionCatalogTask)
            }
            assembleTask != null -> assembleTask.dependsOn(buildVersionCatalogTask)
            else -> project.logger.warn(warningMessage)
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy