Gradle: How do I configure a plugin extension (eg. checkstyle {...}) for all subprojects?

Saket Mehta :

I have the following in my root build.gradle file.

subprojects {
    apply plugin: 'checkstyle'

    checkstyle {
        maxWarnings = 0
    }
}

But it seems IntelliJ only recognizes the checkstyle extension block if I put the above in a allprojects block. The IDE simply greys out the checkstyle keyword and underlines it with a squiggly line. See the image for reference.

checkstyle config not recognized

When put under the allprojects block, it works fine:

enter image description here

Can someone explain to me what is happening here? If this is just an IDE thing, would love to have some insight into why this might be happening.

Stanislav :

I suppose it's just an IDE thing and happens because in case you are using the allproject configuration, then your current project is getting a checkstyle plugin applied too, like all it's child projects, and IDE can find a checkstyle configuration closure.

Opposite, if you are using the subproject, your current project configuration doesn't have a checkstyle plugin apllied and IDE can't see a closure to configure it in the scope of this project.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=165385&siteId=1