Checkstyle:CheckstyleException:无法找到但文件存在
Checkstyle: CheckstyleException: Unable to find but file exists
我的 Checkstyle 配置似乎找不到我的 suppressions.xml,但它确实存在并且它使用的文件路径有效。我的 checkstyle.xml 和 suppressions.xml 都在 config/checkstyle。我的 checkstyle.xml 有这个:
<module name="SuppressionFilter">
<property name="file" value="${config_loc}\suppressions.xml"/>
<property name="optional" value="false"/>
</module>
当我 运行 gradlew check --stacktrace
时,堆栈跟踪显示如下:
Caused by: com.puppycrawl.tools.checkstyle.api.CheckstyleException: Unable to find: C:\Users\ntroncoso\Online Drive\projects\test-project\test-project-sdk\config\checkstyle\suppressions.xml
at com.puppycrawl.tools.checkstyle.filters.SuppressionsLoader.getSuppressionLoader(SuppressionsLoader.java:287)
at com.puppycrawl.tools.checkstyle.filters.SuppressionsLoader.loadSuppressions(SuppressionsLoader.java:238)
at com.puppycrawl.tools.checkstyle.filters.SuppressionsLoader.loadSuppressions(SuppressionsLoader.java:224)
at com.puppycrawl.tools.checkstyle.filters.SuppressionFilter.finishLocalSetup(SuppressionFilter.java:269)
at com.puppycrawl.tools.checkstyle.api.AutomaticBean.configure(AutomaticBean.java:197)
at com.puppycrawl.tools.checkstyle.Checker.setupChild(Checker.java:477)
... 206 more
Caused by: java.io.FileNotFoundException: http://www.puppycrawl.com/dtds/configuration_1_3.dtd
at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.setupCurrentEntity(XMLEntityManager.java:647)
at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.startEntity(XMLEntityManager.java:1304)
at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.startDTDEntity(XMLEntityManager.java:1270)
at com.sun.org.apache.xerces.internal.impl.XMLDTDScannerImpl.setInputSource(XMLDTDScannerImpl.java:264)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$DTDDriver.dispatch(XMLDocumentScannerImpl.java:1161)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$DTDDriver.next(XMLDocumentScannerImpl.java:1045)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$PrologDriver.next(XMLDocumentScannerImpl.java:959)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:602)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:505)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:842)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:771)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:141)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1213)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:643)
at com.puppycrawl.tools.checkstyle.XmlLoader.parseInputSource(XmlLoader.java:86)
at com.puppycrawl.tools.checkstyle.filters.SuppressionsLoader.getSuppressionLoader(SuppressionsLoader.java:283)
正如我提到的,我可以将该文件路径复制并粘贴到文件资源管理器中,它会打开。我也尝试对完整路径进行硬编码,但我得到了同样的错误。我唯一能想到的是 \ntroncoso 部分。一些系统会将其视为路径中的新行。但通常情况下,错误也会打印新行,所以我不觉得这是问题所在。
FileNotFoundException: http://www.puppycrawl.com/dtds/configuration_1_3.dtd
这才是你真正的错误。你的抑制文件的 DTD 是错误的。首先,您正在使用抑制文件的配置 DTD。其次,puppycrawl 域已过时并已移至 checkstyle.org .
DTD 应该更改为 https://checkstyle.org/dtds/suppressions_1_2.dtd
,这是目前最新版本的 Checkstyle 的最新 DTD。
请参阅 https://github.com/checkstyle/checkstyle/blob/master/config/suppressions.xml 以获取正确抑制文件的示例。
我的 Checkstyle 配置似乎找不到我的 suppressions.xml,但它确实存在并且它使用的文件路径有效。我的 checkstyle.xml 和 suppressions.xml 都在 config/checkstyle。我的 checkstyle.xml 有这个:
<module name="SuppressionFilter">
<property name="file" value="${config_loc}\suppressions.xml"/>
<property name="optional" value="false"/>
</module>
当我 运行 gradlew check --stacktrace
时,堆栈跟踪显示如下:
Caused by: com.puppycrawl.tools.checkstyle.api.CheckstyleException: Unable to find: C:\Users\ntroncoso\Online Drive\projects\test-project\test-project-sdk\config\checkstyle\suppressions.xml
at com.puppycrawl.tools.checkstyle.filters.SuppressionsLoader.getSuppressionLoader(SuppressionsLoader.java:287)
at com.puppycrawl.tools.checkstyle.filters.SuppressionsLoader.loadSuppressions(SuppressionsLoader.java:238)
at com.puppycrawl.tools.checkstyle.filters.SuppressionsLoader.loadSuppressions(SuppressionsLoader.java:224)
at com.puppycrawl.tools.checkstyle.filters.SuppressionFilter.finishLocalSetup(SuppressionFilter.java:269)
at com.puppycrawl.tools.checkstyle.api.AutomaticBean.configure(AutomaticBean.java:197)
at com.puppycrawl.tools.checkstyle.Checker.setupChild(Checker.java:477)
... 206 more
Caused by: java.io.FileNotFoundException: http://www.puppycrawl.com/dtds/configuration_1_3.dtd
at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.setupCurrentEntity(XMLEntityManager.java:647)
at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.startEntity(XMLEntityManager.java:1304)
at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.startDTDEntity(XMLEntityManager.java:1270)
at com.sun.org.apache.xerces.internal.impl.XMLDTDScannerImpl.setInputSource(XMLDTDScannerImpl.java:264)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$DTDDriver.dispatch(XMLDocumentScannerImpl.java:1161)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$DTDDriver.next(XMLDocumentScannerImpl.java:1045)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$PrologDriver.next(XMLDocumentScannerImpl.java:959)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:602)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:505)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:842)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:771)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:141)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1213)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:643)
at com.puppycrawl.tools.checkstyle.XmlLoader.parseInputSource(XmlLoader.java:86)
at com.puppycrawl.tools.checkstyle.filters.SuppressionsLoader.getSuppressionLoader(SuppressionsLoader.java:283)
正如我提到的,我可以将该文件路径复制并粘贴到文件资源管理器中,它会打开。我也尝试对完整路径进行硬编码,但我得到了同样的错误。我唯一能想到的是 \ntroncoso 部分。一些系统会将其视为路径中的新行。但通常情况下,错误也会打印新行,所以我不觉得这是问题所在。
FileNotFoundException: http://www.puppycrawl.com/dtds/configuration_1_3.dtd
这才是你真正的错误。你的抑制文件的 DTD 是错误的。首先,您正在使用抑制文件的配置 DTD。其次,puppycrawl 域已过时并已移至 checkstyle.org .
DTD 应该更改为 https://checkstyle.org/dtds/suppressions_1_2.dtd
,这是目前最新版本的 Checkstyle 的最新 DTD。
请参阅 https://github.com/checkstyle/checkstyle/blob/master/config/suppressions.xml 以获取正确抑制文件的示例。