Search code examples
gradlecodenarc

How create a single CodeNarc report for a multiple-project Gradle build


I have a Gradle multi-projects build where each subproject creates its own CodeNarc report.

Is it possibile to create a single CodeNarc analysis report for all the projects in my build instead of a separate report for each of them?


Solution

  • You can create your own CodeNarc task and configure it with the sourcesets of all its subprojects as follows.

    task supernarc(type: CodeNarc) {
      def allGroovySourceDirs = subprojects.collect { Project p -> p.sourceSets.main.allGroovy.getSrcDirs() }.flatten()
    
      allGroovySourceDirs.each {
        source(it)
      }
    
      // BTW, if you know you have some violations and don't want the builds to fail because of too many violations, you can increase the threshold as follows
      maxPriority1Violations = 5
      maxPriority2Violations = 5
      maxPriority3Violations = 5
    

    }

    I created this sample on Github for you so you could see a project using it.

    Does that help?

    Cheers Kon