2

I am trying to have Checkstyle XML implementation in to my project. I have below included in my pom.xml and I have my checkstyle-checker.xml in the same location as my project.

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.17</version>
<configuration>
<configLocation>checkstyle-checker.xml</configLocation>
</configuration>
</plugin>
</plugins>
</build>
</project>
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE module PUBLIC
"-//Puppy Crawl//DTD Check Configuration 1.1//EN"
"http://www.puppycrawl.com/dtds/configuration_1_1.dtd">

<module name="Checker">
<module name="TreeWalker">
<module name="EmptyBlock">
<property name="option" value="stmt" />
<property name="severity" value="error" />
<property name="tokens"
value="LITERAL_DO, LITERAL_ELSE, LITERAL_FINALLY, LITERAL_IF, LITERAL_FOR, LITERAL_TRY, LITERAL_WHILE, STATIC_INIT" />
</module>

<module name="EmptyBlock">
<property name="option" value="text" />
<property name="severity" value="error" />
<property name="tokens" value="LITERAL_CATCH" />
</module>

<module name="MissingSwitchDefault">
<property name="severity" value="error" />
</module>

<module name="StringLiteralEquality">
<property name="severity" value="error" />
</module>

<module name="JavadocStyle">
<property name="checkEmptyJavadoc" value="false" />
<property name="checkFirstSentence" value="false" />
<property name="checkHtml" value="true" />
<property name="scope" value="private" />
<property name="severity" value="error" />
<property name="tokens"
value="INTERFACE_DEF, CLASS_DEF, METHOD_DEF, CTOR_DEF, VARIABLE_DEF" />
</module>

<module name="ConstantName">
<property name="format" value="^[A-Z](_?[A-Z0-9]+)*$" />
<property name="severity" value="error" />
</module>

<module name="MemberName">
<property name="applyToPackage" value="true" />
<property name="applyToPrivate" value="true" />
<property name="applyToProtected" value="true" />
<property name="applyToPublic" value="true" />
<property name="format" value="^[a-zA-Z][a-zA-Z0-9]*$" />
<property name="severity" value="warning" />
</module>

<module name="MethodName">
<property name="format" value="^[a-z][a-zA-Z0-9]*$" />
<property name="severity" value="error" />
</module>

<module name="ParameterName">
<property name="format" value="^[a-z][a-zA-Z0-9]*$" />
<property name="severity" value="error" />
</module>

<module name="TypeName">
<property name="format" value="^[A-Z][a-zA-Z0-9]*$" />
<property name="severity" value="error" />
<property name="tokens" value="CLASS_DEF, INTERFACE_DEF" />
</module>

<module name="NeedBraces">
<property name="tokens"
value="LITERAL_DO, LITERAL_ELSE, LITERAL_IF, LITERAL_FOR, LITERAL_WHILE" />
<property name="severity" value="error" />
</module>

<module name="RedundantImport">
<property name="severity" value="error" />
</module>

<module name="SimplifyBooleanReturn">
<property name="severity" value="warning" />
</module>

<module name="UnusedImports">
<property name="severity" value="error" />
</module>

<module name="ModifierOrder">
<property name="severity" value="error" />
</module>

<module name="MultipleVariableDeclarations">
<property name="severity" value="error" />
</module>

</module>

<module name="SuppressionFilter">
<property name="file" value="${basedir}/suppressions.xml" />
</module>

</module>

When I ran mvn checkstyle:checkstyle I am getting below error. It would be helpful if someone can assist on what is missing.

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-checkstyle-plugin:2.17:checkstyle (default-cli) on project automation-dev: An error has occurred in Checkstyle report generation. Failed during checkstyle execution: Failed during checkstyle configuration: unable to parse configuration stream: Property ${basedir} has not been set -> [Help 1]
4
  • Could you post your checkstyle-checker.xml file? Also, where is it located in your project? Commented Apr 10, 2016 at 17:17
  • Updated with checkstyle-checker.xml. This file is same location as my pom.xml Commented Apr 10, 2016 at 17:30
  • @Tunaki. Thanks for your reference it was able to fix this by removing <module name="SuppressionFilter"> <property name="file" value="${basedir}/suppressions.xml" /> </module>. Commented Apr 10, 2016 at 17:34
  • Refer also to stackoverflow.com/q/3981673/1743880 Commented Apr 10, 2016 at 17:34

1 Answer 1

2

@Tunaki. Thanks for your reference i was able to fix this by removing:

<module name="SuppressionFilter">
  <property name="file" value="${basedir}/suppressions.xml" />
</module>

Reference ${basedir}/suppressions.xml was causing problem in parsing checkstyle-checker.xml as this was non-existent. As an immediate fix i removed it. This can be included as needed when there are specific files that needs to suppressed from checking

Sign up to request clarification or add additional context in comments.

2 Comments

No need to downvote any longer. Just a (now corrected) formatting problem. :)
Could you also add an explanation as to why this fixed the problem?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.