How to generate Codenarc report for Main and Test classes using different rule-sets?

StackOverflow https://stackoverflow.com/questions/14358471

  •  16-01-2022
  •  | 
  •  

Question

I am using CodeNarc for coding best practices in my project and it's working absolutely fine. In general Codenarc makes the report separately for all the Main classes and Test classes based on the rulesets defined in the config file(in my case codenarc.xml). I have used to following code snippet in my project:

apply plugin: 'codenarc'

dependencies {
    codenarc group: 'org.codenarc', name: 'CodeNarc', version: '0.17'
}

codenarc {
    configFile = file('src/conf/codenarc.xml')
}

I don't want to enforce all the rules for both Main and Test classes (e.g. I may want to exclude some rule-sets from Test classes). Is there any way doing that?

Was it helpful?

Solution

You can configure the CodeNarc tasks individually:

codenarcMain {
    configFile = ...
}

codenarcTest {
    configFile = ...
}

PS: I recommend to use shorthand dependency notation:

dependencies {
    codenarc "org.codenarc:CodeNarc:0.17"
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top