所以我目前正在为maven / java项目实现checkstyle。由于我公司的项目复杂而又庞大,我从一个较小的项目开始,只是为了测试它是否有效。到目前为止,执行情况很好。我设置好我的checkstyle.xml并将其连接到pom.xml,全部完成了。同样在报告部分,因为我之后需要一些输出。问题是,正如您从标题中可以看出的那样,它想以某种方式解析某些内容,但是我什至无法访问这些文件。
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 really dont know what else to do, thanks in advance for any help.
I get the checkstyle-result.xml but its empty. before i got a empty xml template back (so it worked, without any todos)
But i still expected a checkstyle.html file for the report.
答案 0 :(得分:0)
您的checkstyle.xml
格式不正确。格式正确的XML文档只有一个根元素。您应该像这样将ImportOrder
和SuppressionXpathSingleFilter
模块放在TreeWalker
下:
<!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>