maven checkstyle插件报错

简介: 问题:checkstyle插件报错 Caused by: com.puppycrawl.tools.checkstyle.api.CheckstyleException: Cannot set property 'file' to 'checkstyle-suppressions.

问题:
checkstyle插件报错

详情:
我在研究docker-maven-plugin插件源码,执行
mvn clean package
报错:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-checkstyle-plugin:2.17:check (validate) on project docker-maven-plugin: Failed during checkstyle configuration: cannot initialize module SuppressionFilter - Cannot set property 'file' to 'checkstyle-suppressions.xml' in module SuppressionFilter: InvocationTargetException: Unable to find: checkstyle-suppressions.xml: http://www.puppycrawl.com/dtds/suppressions_1_0.dtd -> [Help 1]

配置:

  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-checkstyle-plugin</artifactId>
    <version>2.17</version>
    <executions>
      <execution>
        <id>validate</id>
        <phase>validate</phase>
        <configuration>
          <configLocation>checkstyle.xml</configLocation>
          <encoding>UTF-8</encoding>
          <consoleOutput>true</consoleOutput>
          <failsOnError>true</failsOnError>
          <includeTestSourceDirectory>true</includeTestSourceDirectory>
        </configuration>
        <goals>
          <goal>check</goal>
        </goals>
      </execution>
    </executions>
    <configuration>
      <linkXRef>false</linkXRef>
    </configuration>
  </plugin>

排查:
添加参数再次执行
mvn clean package -e -X
有如下
Caused by: com.puppycrawl.tools.checkstyle.api.CheckstyleException: Cannot set property 'file' to 'checkstyle-suppressions.xml' in module SuppressionFilter

    at com.puppycrawl.tools.checkstyle.api.AutomaticBean.tryCopyProperty(AutomaticBean.java:178)
    at com.puppycrawl.tools.checkstyle.api.AutomaticBean.configure(AutomaticBean.java:130)
    at com.puppycrawl.tools.checkstyle.Checker.setupChild(Checker.java:163)
    ... 25 more

Caused by: java.lang.reflect.InvocationTargetException

    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.apache.commons.beanutils.PropertyUtilsBean.invokeMethod(PropertyUtilsBean.java:2116)
    at org.apache.commons.beanutils.PropertyUtilsBean.setSimpleProperty(PropertyUtilsBean.java:2097)
    at org.apache.commons.beanutils.BeanUtilsBean.copyProperty(BeanUtilsBean.java:435)
    at com.puppycrawl.tools.checkstyle.api.AutomaticBean.tryCopyProperty(AutomaticBean.java:168)
    ... 27 more

Caused by: com.puppycrawl.tools.checkstyle.api.CheckstyleException: Unable to find: checkstyle-suppressions.xml

    at com.puppycrawl.tools.checkstyle.filters.SuppressionsLoader.loadSuppressions(SuppressionsLoader.java:147)
    at com.puppycrawl.tools.checkstyle.filters.SuppressionsLoader.loadSuppressions(SuppressionsLoader.java:127)
    at com.puppycrawl.tools.checkstyle.filters.SuppressionFilter.setFile(SuppressionFilter.java:50)
    ... 35 more

Caused by: java.io.FileNotFoundException: http://www.puppycrawl.com/dtds/suppressions_1_0.dtd

    at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1872)
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1474)
    at org.apache.xerces.impl.XMLEntityManager.setupCurrentEntity(Unknown Source)
    at org.apache.xerces.impl.XMLEntityManager.startEntity(Unknown Source)
    at org.apache.xerces.impl.XMLEntityManager.startDTDEntity(Unknown Source)
    at org.apache.xerces.impl.XMLDTDScannerImpl.setInputSource(Unknown Source)
    at org.apache.xerces.impl.XMLDocumentScannerImpl$DTDDispatcher.dispatch(Unknown Source)
    at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
    at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)

文件http://www.puppycrawl.com/dtds/suppressions_1_0.dtd未找到
网站:http://www.puppycrawl.com
06EE02CF3A82444B9F37C0765AAAD652

解决方式:
1.找Oliver Bum要一个suppressions_1_0.dtd
2.删除checkstyle-suppressions.xml文件(会报错)
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-checkstyle-plugin:2.17:check (validate) on project docker-maven-plugin: Failed during checkstyle configuration: cannot initialize module SuppressionFilter - Cannot set property 'file' to 'checkstyle-suppressions.xml' in module SuppressionFilter: InvocationTargetException: Unable to find: checkstyle-suppressions.xml -> [Help 1]
3.自己写一个,如果知道内容可以自己写一个
例如:
修改前:
<?xml version="1.0" encoding="UTF-8"?>
/p>

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



修改后:
文件:checkstyle-suppressions.xml
<?xml version="1.0" encoding="UTF-8"?>




增加文件:suppressions.dtd





相关文章
|
2月前
|
Java Maven
Maven编译报错
Maven编译报错
66 1
|
4月前
|
XML Java Maven
maven总结三: 常用插件
maven总结三: 常用插件
49 3
|
25天前
|
Java 编译器 测试技术
全面理解Maven Compiler Plugin-Maven编译插件
【10月更文挑战第16天】
151 1
|
4月前
|
Java 测试技术 Maven
Maven 插件
Maven包含clean、default(build)、site三大生命周期,分别处理项目清理、部署和文档创建。每个生命周期由多个阶段组成,充当标准化接口,实际工作由插件执行。例如,`mvn clean`调用的是clean生命周期的clean阶段,其实现由maven-clean-plugin插件完成。Maven是一个依赖插件的框架,插件负责任务如生成jar/war、编译、测试、文档和报告。通过`mvn plugin-name:goal-name`命令执行插件目标。
|
3月前
|
Java Maven Spring
Maven重打包问题之maven-shade-plugin插件对于重复的class文件会如何处理
Maven重打包问题之maven-shade-plugin插件对于重复的class文件会如何处理
|
3月前
|
Java jenkins 持续交付
jenkins学习笔记之十七:使用插件及maven上传制品到nexus
jenkins学习笔记之十七:使用插件及maven上传制品到nexus
|
4月前
|
Java Maven
idea安装并使用maven依赖分析插件:Maven Helper
idea安装并使用maven依赖分析插件:Maven Helper
2557 7
|
4月前
|
数据可视化 Java 程序员
IDEA插件-Maven Helper
Maven Helper是一个用于Apache Maven项目的IntelliJ IDEA插件,它提供了一些有用的功能来帮助开发人员更好地管理和调试Maven项目。
577 0
IDEA插件-Maven Helper
|
3月前
|
Java Maven 开发者
"揭秘IDEA的神奇助手:Maven Helper插件,让你轻松驾驭复杂依赖,告别冲突噩梦!"
【8月更文挑战第20天】Maven Helper是一款提升Java开发者工作效率的IDEA插件,它能直观展示项目依赖关系并协助管理。主要功能包括依赖树视图、冲突检测与解决及依赖排除。安装简便,重启IDEA后即用。借助其“Dependencies”面板,开发者可以清晰了解依赖详情,快速定位并解决冲突问题,有效优化项目结构,提升开发效率。
227 0
|
4月前
|
Java 测试技术 Maven
Maven 插件
Maven包含clean、default/build、site三个生命周期,用于清理、构建和文档创建。每个生命周期由多个阶段构成,作为标准化步骤。比如`mvn clean`调用Clean生命周期的clean阶段,其实体实现是maven-clean-plugin。Maven依赖插件执行任务,如生成jar/war、编译、测试、文档等。插件通过`mvn plugin-name:goal-name`形式执行特定目标。