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

main.name.remal.gradle_plugins.plugins.dependencies.ComponentCapabilitiesPlugin.kt Maven / Gradle / Ivy

There is a newer version: 1.9.2
Show newest version
package name.remal.gradle_plugins.plugins.dependencies

import name.remal.Services.loadImplementationClasses
import name.remal.gradle_plugins.dsl.BaseReflectiveProjectPlugin
import name.remal.gradle_plugins.dsl.GradleEnumVersion.GRADLE_VERSION_4_9
import name.remal.gradle_plugins.dsl.MinGradleVersion
import name.remal.gradle_plugins.dsl.Plugin
import name.remal.gradle_plugins.dsl.PluginAction
import name.remal.gradle_plugins.dsl.utils.wrapWithInjectedConstructorParams
import name.remal.uncheckedCast
import org.gradle.api.Project
import org.gradle.api.artifacts.dsl.DependencyHandler

@Plugin(
    id = "name.remal.component-capabilities",
    description = "Plugin that configures some default component capabilities.",
    tags = ["capabilities", "component-capabilities"]
)
@MinGradleVersion(GRADLE_VERSION_4_9)
class ComponentCapabilitiesPlugin : BaseReflectiveProjectPlugin() {

    companion object {
        private val capabilitiesClasses: List> by lazy {
            sequenceOf(
                AbstractComponentCapabilities::class.java,
                AbstractMavenCentralComponentCapabilities::class.java
            )
                .flatMap { loadImplementationClasses(it).asSequence() }
                .distinct()
                .map { it.uncheckedCast>() }
                .toList()
        }
    }

    @PluginAction(isHidden = true)
    protected fun DependencyHandler.registerComponentCapabilities(project: Project) {
        capabilitiesClasses.forEach { capabilitiesClass ->
            val wrappedCapabilitiesClass = wrapWithInjectedConstructorParams(capabilitiesClass, project)
            components.all(wrappedCapabilitiesClass)
        }
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy