Configure third party plugin inside custom plugin

Hi I’m writing a custom gradle plugin class in kotlin-dsl

I’m facing a problem that i cannot access class from third party plugin within the custom plugin function (to configure the plugin extension)

I have tried to make a TestPlugin.kt file with

open class TestPlugin: Plugin<Project> {
    override fun apply(target: Project) {
       configurePlugins(target)
    }
}

internal fun configurePlugins(project: Project) {
    project.plugins.apply("io.gitlab.arturbosch.detekt")

    project.configure<DetektExtension> {
        parallel = true
        ignoreFailures = true
        baseline = file("${rootProject.projectDir}/detekt-baseline.xml")
    }
}

The problem is that there is no import for DetektExtension (while putting configure<> in normal build.gradle.kts file work ok (this make the above wont compile, cannot import DetektExtension

in normal build.gradle.kts i can config

plugins {
   id("io.gitlab.arturbosch.detekt") version "1.1.1"
}

subprojects {
   apply(plugin = "io.gitlab.arturbosch.detekt")
   configure<DetektExtension> {
        parallel = true
        ignoreFailures = true
        baseline = file("${rootProject.projectDir}/detekt-baseline.xml")
   }
}

Any suggestion how to access class of third party plugin inside custom gralde plugin? Thanks

1 Like