Search code examples
mavenantgroovycodenarc

Some CodeNarc rules throwing ClassNotFoundException


So I'm using CodeNarc as an ant task in maven.

For my custom ruleset, I'm able to use IllegalRegexRule. However, when I try to add something else, I sometimes get a ClassNotFoundException.

For example, once I've added this to my ruleset.xml

<rule class='org.codenarc.rule.formatting.MissingBlankLineAfterPackage'>
    <property name='priority' value='1'/>
</rule>

I see

Failed to execute goal org.apache.maven.plugins:maven-antrun-plugin:1.7:run (codenarc) on project myProject: An Ant BuildException has occured: java.lang.ClassNotFoundException: org.codenarc.rule.formatting.MissingBlankLineAfterPackage

Any idea why this would be happening? I'm using version 0.18 of codenarc, here's the ant dependency for CodeNarc:

<dependency>
    <groupId>org.codenarc</groupId>
    <artifactId>CodeNarc</artifactId>
    <version>0.18</version>
    <exclusions>
        <exclusion>
            <groupId>ant</groupId>
                <artifactId>ant</artifactId>
        </exclusion>
    </exclusions>
</dependency>

Edit: This problem still happens on version 0.21


Solution

  • Turns out I was just making a typo. You need to use:

    <rule class='org.codenarc.rule.formatting.MissingBlankLineAfterPackageRule'>
        <property name='priority' value='1'/>
    </rule>
    

    Notice the 'Rule' at the end of the class name.