maven-checkstyle-plugin:3.0.0:check: Failed during checkstyle configuration: cannot initialize module StrictDuplicateCode

Georgy Petukhov picture Georgy Petukhov · Apr 2, 2018 · Viewed 12k times · Source

That's the full error:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-checkstyle-plugin:3.0.0:check (default) on project abc-123-micro-service: Failed during checkstyle configuration: cannot initialize module StrictDuplicateCode - Unable to instantiate 'StrictDuplicateCode' class, it is also not possible to instantiate it as .StrictDuplicateCode, StrictDuplicateCodeCheck, .StrictDuplicateCodeCheck. Please recheck that class name is specified as canonical name or read how to configure short name usage http://checkstyle.sourceforge.net/config.html#Packages. Please also recheck that provided ClassLoader to Checker is configured correctly. -> [Help 1]

My maven configuration for checkstyle plugin:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-checkstyle-plugin</artifactId>
    <version>3.0.0</version>
    <dependencies>
        <dependency>
            <groupId>com.puppycrawl.tools</groupId>
            <artifactId>checkstyle</artifactId>
            <version>8.8</version>
        </dependency>
    </dependencies>
    <executions>
        <execution>
            <id>validate</id>
            <phase>validate</phase>
            <configuration>
                <configLocation>checkstyle.xml</configLocation>
                <encoding>UTF-8</encoding>
                <consoleOutput>true</consoleOutput>
                <failsOnError>true</failsOnError>
            </configuration>
            <goals>
                <goal>check</goal>
            </goals>
        </execution>
    </executions>
</plugin>

My checkstyle.xml config file doesn't contain any of the 'duplicate' rules mentioned in the error. How can I fix this problem and let all the checks pass?

EDIT: The contents of checkstyle.xml: https://pastebin.com/kuJAFiiP

Answer

barfuin picture barfuin · Apr 2, 2018

The error message cannot initialize module StrictDuplicateCode indicates that Checkstyle fails to initialize a check that it found while traversing the config file. Also, the StrictDuplicateCode check was removed in Checkstyle 6.2.

Now since your config file does not reference this check, it must be that the Maven Checkstyle Plugin reads some other config file. Its docs say that configuration should go directly under plugin. Try moving the configuration XML element up.