On 10/08/10 4:37 PM, Matthias Bohlen wrote:
Hi,

I am using the code quality plugin that invokes Checkstyle on my source code. There is a checking rule called "magic number" that I'd like to apply only to the main source set, not to the test source set. "Magic numbers" are numbers other than 0 or 1, and the rule says "make them a static final variable". In test cases, however, I have tons of those concrete magic numbers for which I do not want to create Java constants at all.

So, how do I apply different checkstyle.xml configurations files to the main and to the test source sets?

The Checkstyle task has a 'configFile' property, which you can change to point to a different configuration file. For example:

checkstyleTest {
    configFile = file('config/checkstyle/tests.xml')
}

Another approach, if you don't want to maintain separate config files, is to switch individual rules off using properties. For example in your checkstyle config file:

<module name="MagicNumber">
<property name="severity" value="${magicNumberSeverity}"/>
</module>

And in your build file:

checkstyleMain.properties.magicNumberSeverity = 'error'
checkstyleTest.properties.magicNumberSeverity = 'ignore'


--
Adam Murdoch
Gradle Developer
http://www.gradle.org
CTO, Gradle Inc. - Gradle Training, Support, Consulting
http://www.gradle.biz


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

   http://xircles.codehaus.org/manage_email


Reply via email to