Reputation: 61
I am currently working on implementing checkstyle for maven/java projects. As the project of my company is way to complex and way too big, i started off with a smaller project just to test if it works. Implementation was good so far. I set up my checkstyle.xml
connected it to the pom.xml
, all set up. Also in the reporting section, as i want some output afterwards. The problem is, that somehow it wants to parse something, but I don't even have access to those files.
CheckStyle.xml :
<!DOCTYPE module PUBLIC
"-//Puppy Crawl//DTD Check Configuration 1.3//EN"
"http://www.puppycrawl.com/dtds/configuration_1_3.dtd">
<module name="Checker">
<module name="TreeWalker">
<module name="AvoidStaticImport">
<property name="excludes"
value="java.lang.System.out,java.lang.Math.*" />
</module>
</module>
</module>
<module name="ImportOrder">
<property name="groups" value="*,javax,java"/>
<property name="ordered" value="true"/>
<property name="separated" value="false"/>
<property name="option" value="top"/>
<property name="sortStaticImportsAlphabetically" value="true"/>
</module>
<module name="SuppressionXpathSingleFilter">
<property name="checks" value="ImportOrder"/>
<property name="message" value="^'java\..*'.*"/>
</module>
pom.xml:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<configLocation>checkstyle.xml</configLocation>
</configuration>
<executions>
<execution>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<configLocation>checkstyle.xml</configLocation>
</configuration>
</plugin>
</plugins>
</reporting><!---->
<dependencies>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.9</version>
</dependency>
</dependencies>
Stack Trace:
[INFO] --- maven-checkstyle-plugin:3.1.0:check (default) @ testHelloWorld ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.464 s
[INFO] Finished at: 2019-07-17T11:34:20+02:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-checkstyle-plugin:3.1.0:check (default) on project testHelloWorld: Failed during checkstyle execution: Failed during checkstyle configuration: unable to parse configuration stream - The markup in the document following the root element must be well-formed.:11:3 -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-checkstyle-plugin:3.1.0:check (default) on project testHelloWorld: Failed during checkstyle execution
Caused by: org.apache.maven.plugin.MojoExecutionException: Failed during checkstyle execution
Caused by: org.apache.maven.plugins.checkstyle.exec.CheckstyleExecutorException: Failed during checkstyle configuration
Caused by: com.puppycrawl.tools.checkstyle.api.CheckstyleException: unable to parse configuration stream - The markup in the document following the root element must be well-formed.:11:3
As well as: Caused by: org.xml.sax.SAXParseException: The markup in the document following the root element must be well-formed.
I get the checkstyle-result.xml
, but it's empty. Before I got an empty XML template back, so it worked, without any todos. I still expected a checkstyle.html
file for the report.
Upvotes: 6
Views: 13138
Reputation: 2358
Your checkstyle.xml
is not well-formed. A well-formed XML document has a single root element. You should place your ImportOrder
and SuppressionXpathSingleFilter
modules under the TreeWalker
like this:
<!DOCTYPE module PUBLIC
"-//Puppy Crawl//DTD Check Configuration 1.3//EN"
"http://www.puppycrawl.com/dtds/configuration_1_3.dtd">
<module name="Checker">
<module name="TreeWalker">
<module name="AvoidStaticImport">
<property name="excludes" value="java.lang.System.out,java.lang.Math.*"/>
</module>
<module name="ImportOrder">
<property name="groups" value="*,javax,java"/>
<property name="ordered" value="true"/>
<property name="separated" value="false"/>
<property name="option" value="top"/>
<property name="sortStaticImportsAlphabetically" value="true"/>
</module>
<module name="SuppressionXpathSingleFilter">
<property name="checks" value="ImportOrder"/>
<property name="message" value="^'java\..*'.*"/>
</module>
</module>
</module>
Upvotes: 3