Maven checkstyle plugin: Caused by: com.puppycrawl.tools.checkstyle.api.CheckstyleException

I am trying to configure checkstyle plugin with gradle (in a java 11) project as follows:

checkstyle { toolVersion = '8.2' configFile = rootProject.file('config/checkstyle/checkstyle.xml') configProperties = [ 'checkstyle.cache.file': "${buildDir}/checkstyle.cache", ] ignoreFailures = true showViolations = true } 

My checkstyle.xml is like as follows:

<?xml version="1.0"?> <code_scheme name="CustomStyle" version="1"> <AndroidXmlCodeStyleSettings> <option name="USE_CUSTOM_SETTINGS" value="true"/> <option name="LAYOUT_SETTINGS"> <value> <option name="INSERT_BLANK_LINE_BEFORE_TAG" value="false"/> </value> </option> 

......

And I am getting the below exception

Caused by: com.puppycrawl.tools.checkstyle.api.CheckstyleException: unable to parse configuration stream - Document is invalid: no grammar found.:3:13 at com.puppycrawl.tools.checkstyle.ConfigurationLoader.loadConfiguration(ConfigurationLoader.java:441) at com.puppycrawl.tools.checkstyle.ConfigurationLoader.loadConfiguration(ConfigurationLoader.java:386) at com.puppycrawl.tools.checkstyle.ant.CheckstyleAntTask.createRootModule(CheckstyleAntTask.java:407) ... 106 more Caused by: org.xml.sax.SAXParseException; systemId: file:/home/workspace/service/config/checkstyle/checkstyle.xml; lineNumber: 3; columnNumber: 13; Document is invalid: no grammar found.

Any pointers to fix this issue?

2 Answers

My checkstyle.xml is like as follows:
<code_scheme name="CustomStyle" version="1">

This not the correct markup for checkstyle. Checkstyle configurations are like:

<?xml version="1.0"?> <!DOCTYPE module PUBLIC "-//Puppy Crawl//DTD Check Configuration 1.3//EN" ""> <module name="Checker"> <property name="charset" value="UTF-8"/> <module name="TreeWalker"> </module> </module> 

You can read for more information.

It looks like what you have given it was an IntelliJ configuration file. Either way, it is not compatible with checkstyle.

you need to define what to check against; for example:

<!DOCTYPE module PUBLIC "-//Checkstyle//DTD Checkstyle Configuration 1.3//EN" ""> 

which should be one of these .dtd files.

2

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

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

You Might Also Like