Gradle CodeNarc Plugin - How to change target folder for the scan

According to the CodeNarc Plugin docs, you have to give it particular SourceSets.

According to the SourceSets docs, you could create a custom SourceSet with something like this:


...

sourceSets {
    narcOn {
        groovy {
            srcDir file('foo/src/bar/groovy') /*...If you want to add just one custom one...*/
        }
    }
}
...
codenarc{ 

    ...
    sourceSets narcOn /* not strictly neccessary; codenarc should automatically detect it without this*/
    ...

}

OR

...

sourceSets {
    narcOn {
         groovy {
            srcDirs = ['foo', 'fizz', 'buzz'] /*...If you want more than one custom ones...*/
         }
    }
    ...
}
...

OR

...

sourceSets {
    main {
        groovy {
            srcDir file('src/core') /*...If you want to add a custom one to the conventional 'main' one...*/
        }
    }
}
...

That’ll get you codenarc tasks you could call with either gradle codenarcNarcOn... or gradle codenarcMain....

If that doesn’t work for you, please get back to share whichever solution you do finally end up doing? Thanks.

1 Like