Checkstyle: Use of checkstyle and maven misses checkstyle-checker.xml

Created on 12 May 2015  路  5Comments  路  Source: checkstyle/checkstyle

Hi,

I am currently trying to include checkstyle into my build process. As I am using maven and have configured the plugin like follows:

                      <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-checkstyle-plugin</artifactId>
                <version>2.15</version>
                <configuration>
                    <configLocation>src/main/checkstyle/checkstyle.xml</configLocation>
                </configuration>
            </plugin>

My checkstyle.xml just looks like the basic xml from http://checkstyle.sourceforge.net/config.html:

<?xml version="1.0"?>
<module name="MyChecker">
    <module name="JavadocPackage"/>
    <module name="TreeWalker">
        <module name="AvoidStarImport"/>
        <module name="ConstantName"/>
        <module name="EmptyBlock"/>
    </module>
</module>

Unfortunately, this leads to an error in the build process when executing mvn checkstyle:check :

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-checkstyle-plugin:2.15:check (default-cli) on project backend-server: Failed during checkstyle execution: Failed during checkstyle configuration: unable to read /home/reichelt/workspaces/irpsimworkspace/backend/backend-server/target/checkstyle-checker.xml - unable to parse configuration stream - Document is invalid: no grammar found.:2:8 -> [Help 1]

This error seems to occur also to this guys: http://stackoverflow.com/questions/27273325/problems-with-specifying-headerfile-property-in-checkstyle-plugin-in-maven and http://stackoverflow.com/questions/19682455/how-to-externalise-the-checkstyle-config-for-maven-checkstyle-plugin?rq=1 - for some reason, it searches for the file checkstyle-checker.xml. As the second so-question seems to resolve this issue mainly by addind a suppressionsLocation, I've done the same.

According to http://checkstyle.sourceforge.net/config.html, suppressions are only needed if a suppressions filter is used - is this right, and this is a bug, or am I using this wrong?

After using a right, empty suppressions-xml, the main error with checkstyle-checker.xml occurs again. Is this a bug, and if not, what am I doing wrong?

Most helpful comment

exception is expected, required part of config file (link to schema) is missed :

<!DOCTYPE module PUBLIC
          "-//Puppy Crawl//DTD Check Configuration 1.3//EN"
          "http://www.puppycrawl.com/dtds/configuration_1_3.dtd">

to resolve issue , add schema declaration to xml file

All 5 comments

exception is expected, required part of config file (link to schema) is missed :

<!DOCTYPE module PUBLIC
          "-//Puppy Crawl//DTD Check Configuration 1.3//EN"
          "http://www.puppycrawl.com/dtds/configuration_1_3.dtd">

to resolve issue , add schema declaration to xml file

Thanks, that did it. The right file in the error message maybe could make solving this easier, I thought that the file is somehow wrong specified and not that the grammar is realy wrong.

Using

"-//Puppy Crawl//DTD Check Configuration 1.3//EN"
"http://www.puppycrawl.com/dtds/configuration_1_3.dtd">

Gives this error:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-checkstyle-plugin:2.17:check (default-cli) on project idmgna: Failed during checkstyle execution: Failed during checkstyle configuration: unable to parse configuration stream - The processing instruction target matching "[xX][mM][lL]" is not allowed.:5:10 -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

@zygimantus

The processing instruction target matching "[xX][mM][lL]" is not allowed.:5:10

Your <?xml version="1.0"?> in your config file must start on the first line in the first column. No blank lines or whitespaces must appear before it otherwise you get this error.

Was this page helpful?
0 / 5 - 0 ratings