I am using composite build to manage my plugins. In the same composite build, I have DetektConventionPlugin plugin shown below and I wish to apply it using this pattern: apply<DetektConventionPlugin>(). However, this is not working with composite build but it works for buildSrc but I do not wish to continue using buildSrc.
class DetektConventionPlugin : Plugin<Project> {
override fun apply(target: Project) {
with(target) {
val detektVersion = libs.findVersion("detekt").get().toString()
pluginManager.apply("io.gitlab.arturbosch.detekt")
extensions.getByType<DetektExtension>().apply {
toolVersion = detektVersion
source = files("$rootDir/")
parallel = true
config = files("$rootDir/config/detekt/detekt-config.yml")
buildUponDefaultConfig = true
allRules = false
baseline = file("$rootDir/config/detekt/detekt-baseline.xml")
// dependencies {
// "detektPlugins"(libs.findLibrary("detekt-formatting").get())
// }a
}
tasks.named<Detekt>("detekt").configure {
description = "Runs Detekt on the whole project at once."
reports {
html.required.set(true)
html.outputLocation.set(
file("$rootDir/build/reports/detekt.html"),
)
}
parallel = true
setSource(projectDir)
include("**/*.kt", "**/*.kts")
exclude("**/resources/**", "**/build/**")
// exclude other custom generated files
}
dependencies {
detekt("io.gitlab.arturbosch.detekt:detekt-cli:$detektVersion")
}
}
}
}
I am not sure what I am doing wrong here. Looks like buildSrc handles plugins differently.
Jerry Okafor
I hope you're doing well! And I also hope this help!
You have to register your plugins on Gradle.
In this example I'm using Kotlin DSL.
Than you can call your plugin by ID in any file
I have a project that I use it plugins with Kotlin DSL in my Github.
Project = https://github.com/tavieto/movie-library-android
Plugin directory = https://github.com/tavieto/movie-library-android/blob/main/build-logic/convention/src/main/java/AndroidJetpackCompose.kt
Plugin registration = https://github.com/tavieto/movie-library-android/blob/main/build-logic/convention/build.gradle.kts
Plugin utilization = https://github.com/tavieto/movie-library-android/blob/main/feature/main/build.gradle.kts