gradle checkstyle中无法处理文件错误

问题描述 投票:0回答:1

运行 gradle checkstyle 任务时出现错误:

Unable to process files: [(array of files)]

奇怪的是,如果我重置更改,它就可以正常工作。有什么想法吗?

更新我发现了导致问题的代码行。就是这一行:

if (!(o instanceof final MyObject that)) {

该行使用 Java 16 功能,它为我编译,因为这是我正在使用的 java 版本。然而,它似乎会导致 checkstyle 中断。 当我将此行转换为传统 Java(没有变量声明)时,checkstyle 工作正常。 这看起来很糟糕,有人经历过吗?

java gradle checkstyle
1个回答
0
投票

运行同样的问题。 我通过排除 checkstyle 扫描的 module-info.java 解决了这个问题。 在 build.gradle.kts 中我添加了 checkstyle 配置:

tasks.withType<Checkstyle>().configureEach {
config = resources.text.fromFile("${project.rootProject.rootDir.path}/${System.getProperty("checkstyleInputDir")}/checkstyle.xml");
configDirectory.set(file("${project.rootProject.rootDir.path}/${System.getProperty("checkstyleInputDir")}"));
ignoreFailures = true;
reports {
    xml.required.set(true);
    html.required.set(false);
}
exclude("**/module-info.java");

}

看这一行:exclude("**/module-info.java");。 这将使 checkstyle 跳过模块文件。

© www.soinside.com 2019 - 2024. All rights reserved.