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





相关文章
|
4月前
|
Java Maven
Maven编译报错
Maven编译报错
79 1
|
15天前
|
Java Maven
Maven编译报错:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.13.0:compile 解决方案
在执行Maven项目中的`install`命令时,遇到编译插件版本不匹配的错误。具体报错为:`maven-compiler-plugin:3.13.0`要求Maven版本至少为3.6.3。解决方案是将Maven版本升级到3.6.3或降低插件版本。本文详细介绍了如何下载、解压并配置Maven 3.6.3,包括环境变量设置和IDEA中的Maven配置,确保项目顺利编译。
Maven编译报错:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.13.0:compile 解决方案
|
15天前
|
缓存 Java Maven
【简单四步教你解决♥十分有效】Maven依赖报错、依赖或插件导入失败的万能解决办法
【简单四步教你解决♥十分有效】Maven依赖报错、依赖或插件导入失败的万能解决办法!在处理Maven项目问题时,首先检查Maven配置是否正确。接着通过“File--Invalidata Caches”清除IDEA缓存并重启。使用Maven命令`mvn dependency:purge-local-repository`和`mvn dependency:resolve`清除本地依赖缓存。最后,在Terminal中输入`mvn clean install`完成构建。
【简单四步教你解决♥十分有效】Maven依赖报错、依赖或插件导入失败的万能解决办法
|
14天前
|
存储 Java Linux
【Maven】——基础入门,插件安装、配置和简单使用,Maven如何设置国内源
Maven插件安装,Maven项目构建,依赖管理,Haven Help插件,Maven仓库,Maven如何设置国内源
|
6月前
|
XML Java Maven
maven总结三: 常用插件
maven总结三: 常用插件
61 3
|
6月前
|
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 Compiler Plugin-Maven编译插件
【10月更文挑战第16天】
569 1
|
5月前
|
Java Maven Spring
Maven重打包问题之maven-shade-plugin插件对于重复的class文件会如何处理
Maven重打包问题之maven-shade-plugin插件对于重复的class文件会如何处理
111 2
|
6月前
|
Java Maven
idea安装并使用maven依赖分析插件:Maven Helper
idea安装并使用maven依赖分析插件:Maven Helper
2733 7
|
5月前
|
Java jenkins 持续交付
jenkins学习笔记之十七:使用插件及maven上传制品到nexus
jenkins学习笔记之十七:使用插件及maven上传制品到nexus