Intellij checkstyle - setting path relative to the

2019-02-26 03:49发布

问题:

My company is switching from Eclipse to IntelliJ. In Eclipse we had a following configuration for suppression filters in checkstyle.xml

<module name="SuppressionFilter">
    <property name="file" value="${checkstyle.config.dir}/suppressions.xml"/>
</module>
<module name="SuppressionFilter">
    <property name="file" value="${common.checkstyle.config.dir}/global-suppressions.xml"/>
</module>

Where:

  • common.checkstyle.config.dir was an absolute path to the common project(module in IntelliJ).

  • checkstyle.config.dir was an relative path to the project(module), and has a value of checkstyle.config.dir=${root.dir}/config/checkstyle

We would like to define a path for this file in IntelliJ, so it would look for the suppression filter in each MODULE/config/checkstyle directory(each module has a different suppression).

Does anyone know if it is possible? We have tried to find a solution for quite some time, but no luck so far.

回答1:

Thanks to Thomas Jensen's answer, I solved my very same problem. I answered in detail in this question. Hope it helps.



回答2:

The Checkstyle integration in Eclipse is more powerful in some respects than the one in IntelliJ. This is one such case, I believe.

I would recommend changing the Checkstyle setup so that you have only one Checkstyle configuration and a central suppressions file for all modules. As you will see, modules are more tightly related in IntelliJ than projects are in Eclipse, so this is actually a good idea.

In order to keep module-specific configuration and/or suppressions, you would have to do the following:

  1. Define all of the module-specific configurations in the central Checkstyle settings (so you have module1-rules, module2-rules etc. in your list).
  2. In each module, select the appropriate configuration from the drop-down box.

This is quite a lot of work though, so I think you will find centralizing the configuration more convenient. (By the way, here are the supported variables, none of which will help you, I'm afraid.)