I am using the Checkstyle plugin in IDEA. I want to set up different checkstyle configurations to my different modules. I am using gradle as build tool-version 4- and I want to write a task that modifies the corresponding .iml files of the modules. Any idea how to do that?
My very first attempt in modifying the iml file looking over here
apply plugin: 'idea'
task setCheckStylePluginSettings {
group = "Idea"
description = "Copies CheckStyle plugin settings to Idea workspace."
println "Step 1."
idea.module.iml {
withXml {xmlProvider ->
// Get root node.
println "Step 2."
def project = xmlProvider.asNode()
}
}
}
However, I am stuck just at the beginning that I cant event see the Step 2 printed on the Console.
So the problem is solved. I have tried the solution proposed by Thomas Jansen in this question.
But I will give more information on how to do it.
In order to give different checkstyle modules to different sourcesets you need to define id tag in the module. Shown below:
Then we define SuppressionFilter module for suppression.xml which can be located at the same folder with your checkstyle.xml. One important thing is to locate the SuppressionFilter module as Checker module.
Then, we define the suppression.xml file as below:
Aaaaaand lastly, configure your Checkstyle-IDEA plugin, activate real time scan from Settings>Editor>Inspections>Checkstyle and you are done.
A "module" in IntelliJ is a one-to-one mapping to a SourceSet in Gradle, assuming you imported the project with the "Create separate modules per source set" option checked.
By default, the Checkstyle plugin adds tasks for each source set that is added to the build. So, you should already have the tasks
checkstyleMain
andcheckstyleTest
when you apply thejava
plugin. These tasks are effectively what you're looking for.Now, to customize them, in your
build.gradle
, configure them like so:This assumes that you have different Checkstyle configuration files in your project at
${rootDir}/checkstyle/
.