gradle checkstyle 中无法处理文件错误

Rob*_*Rob 7 java checkstyle gradle

运行 gradle checkstyle 任务时出现错误: Unable to process files: [(array of files)]

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

更新我发现导致问题的代码行。就是这一行: if (!(o instanceof final MyObject that)) {

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

小智 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");
}
Run Code Online (Sandbox Code Playgroud)

看一下这一行:排除(“**/module-info.java”); 。这将使 checkstyle 跳过模块文件。