Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Configure plugin in separate file using Kotlin DSL

to differenciate diferent plugins configurations, I use separate files.

For example:

./build.gradle.kts
./detekt.gradle.kts
./settings.gradle.kts
./module1
./module2
...

In the root build.gradle.kts I have this:

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

buildscript {
    dependencies {
        classpath(io.gitlab.arturbosch.detekt:detekt-gradle-plugin:1.1.1)
    }
}

And to configure it I go to the detekt.gradle.kts and put:

apply(plugin = "io.gitlab.arturbosch.detekt")

detekt {
    // configure
}

But detekt lambda is not found. Also tried with:

apply(plugin = "io.gitlab.arturbosch.detekt")

configure<io.gitlab.arturbosch.detekt.Detekt> {
    // configure
}

But it doesn't find .Detekt.

With JaCoCo I haven't got any problems using the second approach, but it doesn't work with Detekt or SonarQube.

How can I configure plugins in a separate file?

Thanks.

like image 762
allnex Avatar asked Oct 30 '19 21:10

allnex


2 Answers

Try something like below. I have declared a plugin "sonarqube" in my main gradle. I then apply the file sonar.gradle.kts towards the end of the build.gradle.kts file.

    build.gradle.kts:
    plugins {
      id("org.sonarqube") version "2.8" apply false
    }
    ...

    apply(from="$rootDir/gradle/includes/sonar.gradle.kts")    

    gradle/includes/sonar.gradle.kts:
    apply(plugin="org.sonarqube")

Using a setup like above, I can then run "gradle sonarqube"

like image 175
skipy Avatar answered Nov 10 '22 16:11

skipy


I faced a similar issue. Everything that you need to do is to call

configure<io.gitlab.arturbosch.detekt.extensions.DetektExtension> {             
    // configure
}

More info, you can find here: https://docs.gradle.org/current/userguide/migrating_from_groovy_to_kotlin_dsl.html#configuring-plugins

like image 27
Paukdcn Avatar answered Nov 10 '22 15:11

Paukdcn