Checkstyle gradle 使用谷歌检查

pla*_*ton 1 checkstyle gradle

我想通过 gradle checkstyle(v8.42) 插件使用 google 样式检查。

google_checks.xml 是否在插件中可用,或者配置应该从https://github.com/checkstyle/checkstyle/blob/checkstyle-8.42/src/main/resources/google_checks.xml复制?

Fra*_*teo 6

google_checks.xml是已发布的 Checkstyle JAR 的一部分:

checkstyle JAR 内容

因此,您可以使用 Gradle 从 JAR 中检索资源。

下面的将起作用。它是用 Kotlin DSL 编写的,但可以轻松转换为 Groovy DSL。

// build.gradle.kts

plugins {
    id("java")
    id("checkstyle")
}

checkstyle {
    val archive = configurations.checkstyle.get().resolve().filter {
        it.name.startsWith("checkstyle")
    }
    config = resources.text.fromArchiveEntry(archive, "google_checks.xml")
}
Run Code Online (Sandbox Code Playgroud)