问题
I'm trying to create a new quality profile with existing checkstyle ruleset but get the error message:
Rule template can't be activated on a Quality profile: checkstyle:com.puppycrawl.tools.checkstyle.checks.naming.ConstantNameCheck
I use the simplest ruleset example from the checkstyle officail site:
<module name="Checker">
<module name="JavadocPackage"/>
<module name="TreeWalker">
<module name="AvoidStarImport"/>
<module name="ConstantName"/>
<module name="EmptyBlock"/>
</module>
</module>
Versions: Sonar 4.5.1 with Checkstyle plugin 2.1.1
What is wrong?
回答1:
Those Checkstyle rules (like "ConstantNameCheck") are defined with a multiple cardinality in the SonarQube Checkstyle plugin. This means that it should be possible to activate several "instances" of those rules with different values for its parameters.
In SonarQube 4.4+, it is no more possible to have multiple activations of those rules. They are considered as "rule templates", which means that you must create custom rules (with explicit parameters) out of them in order to be able to activate them on quality profiles.
Everything is explained on the Rules documentation page.
回答2:
Look at this.
http://dist.sonarsource.com/reports/coverage/checkstyle.html
It works, when you change it with this parameters. For example ConstantName in checkstyle xml-file is S00115. May be this is the solution.
Example:
<module name="S00115"/> <!--ConstantName-->
<module name="S00117"> <!--LocalFinalVariableName-->
<property name="format" value="^[a-z_][a-zA-Z0-9]*$"/>
</module>
来源:https://stackoverflow.com/questions/26886105/sonar-checkstyle-import-rule-template-cant-be-activated-on-a-quality-profile