TWiStErRob/net.twisterrob.gradle

GitHub: TWiStErRob/net.twisterrob.gradle

一款针对 Android 变体深度优化的 Gradle 代码质量插件,整合 CheckStyle、PMD 和 Lint 并提供统一的报告聚合能力。

Stars: 20 | Forks: 4

[![Continuous Integration](https://github.com/TWiStErRob/net.twisterrob.gradle/actions/workflows/CI.yml/badge.svg)](https://github.com/TWiStErRob/net.twisterrob.gradle/actions/workflows/CI.yml) [![Releases](https://img.shields.io/github/v/release/twisterrob/net.twisterrob.gradle)]( https://github.com/TWiStErRob/net.twisterrob.gradle/releases) [![Maven Central](https://img.shields.io/maven-central/v/net.twisterrob.gradle/twister-quality)]( https://search.maven.org/search?q=g:net.twisterrob.gradle) [![Licence](https://img.shields.io/github/license/twisterrob/net.twisterrob.gradle)]( https://github.com/TWiStErRob/net.twisterrob.gradle/blob/main/LICENCE) [![Twitter](https://img.shields.io/twitter/follow/twisterrob?style=social)]( https://twitter.com/twisterrob) # Gradle Quality 插件 这些插件使用更合理的默认值配置内置插件(待补充文档)。 * CheckStyle * PMD * Android Lint 当前目标是改善 Android 支持,因为涉及到 build types 和 flavors。 有关不同版本变更的详细信息,请参阅 [GitHub Releases](https://github.com/TWiStErRob/net.twisterrob.gradle/releases)。 ## 兼容性 Android Gradle Plugin 3.1.4 — 9.0.1 在 Gradle 4.9 — 9.3.1 上的支持情况,如 [AGP 兼容性指南](https://developer.android.com/studio/releases/gradle-plugin#updating-gradle) 所列,由不同的插件版本覆盖。 当前支持的版本是 Android Gradle Plugin 8.2.1 — 9.0.1 在 Gradle 8.2 — 9.3.1 上(在兼容的情况下)。 | AGP →
Gradle ↓ | 3.1.x | 3.2.x | 3.3.x | 3.4.x | 3.5.x | 3.6.x | 4.0.x | 4.1.x | 4.2.x ^3 | 7.0.x | 7.1.x | 7.2.x | 7.3.x | 7.4.x ^4 | 8.0.x | 8.1.x ^4 | 8.2.x | 8.3.x | 8.4.x | 8.5.x | 8.6.x | 8.7.x | 8.8.x | 8.9.x | 8.10.x | 8.11.x | 8.12.x | 8.13.x | 9.0.x | |:-------------------|:----------:|:----------:|:------------:|:------------:|:-------------:|:-------------:|:-------------:|:-------------:|:-------------:|:-----------:|:-----------:|:-----------:|:-----------:|:-----------:|:-----------:|:-----------:|:--------:|:--------:|:--------:|:--------:|:--------:|:--------:|:--------:|:--------:|:--------:|:--------:|:--------:|:--------:|:--------:| | 4.4 - 4.8.1 | 0.5 - 0.7 | ^1 | × | × | × | × | × | × | × | × | × | × | × | × | × | × | × | × | × | × | × | × | × | × | × | × | × | × | × | | 4.9 - 4.10 | 0.8 - 0.14 | 0.7 - 0.14 | × | × | × | × | × | × | × | × | × | × | × | × | × | × | × | × | × | × | × | × | × | × | × | × | × | × | × | | 4.10.1 - 5.1 | ? | 0.8 - 0.14 | 0.8 - 0.14 | × | × | × | × | × | × | × | × | × | × | × | × | × | × | × | × | × | × | × | × | × | × | × | × | × | × | | 5.1.1 - 5.4 | ? | ? | 0.9 - 0.14 | 0.9 - 0.15.1 | × | × | × | × | × | × | × | × | × | × | × | × | × | × | × | × | × | × | × | × | × | × | × | × | × | | 5.4.1 - 5.6.3 | ? | ? | 0.9 - 0.15.1 | 0.9 - 0.15.1 | sup. | × | × | × | × | × | × | × | × | × | × | × | × | × | × | × | × | × | × | × | × | × | × | × | × | | 5.6.4 | ? | ? | ? | ? | 0.10 - 0.15.1 | 0.10 - 0.15.1 | × | × | × | × | × | × | × | × | × | × | × | × | × | × | × | × | × | × | × | × | × | × | × | | 6.0 - 6.1 | ? | ? | ? | ? | 0.11 - 0.15.1 | 0.11 - 0.15.1 | × | × | × | × | × | × | × | × | × | × | × | × | × | × | × | × | × | × | × | × | × | × | × | | 6.1.1 - 6.4.1 | ? | ? | ? | ? | 0.11 - 0.15.1 | 0.11 - 0.15.1 | 0.11 - 0.15.1 | × | × | × | × | × | × | × | × | × | × | × | × | × | × | × | × | × | × | × | × | × | × | | 6.5 - 6.7 | ? | ? | ? | ? | 0.11 - 0.15.1 | 0.11 - 0.15.1 | 0.11 - 0.15.1 | 0.11 - 0.15.1 | × | × | × | × | × | × | × | × | × | × | × | × | × | × | × | × | × | × | × | × | × | | 6.7.1 - 6.9.4 ^3 | ? | ? | ? | ? | ? | ? | ? | 0.11 - 0.15.1 | 0.11 - 0.15.1 | × | × | × | × | × | × | × | × | × | × | × | × | × | × | × | × | × | × | × | × | | 7.0 - 7.1.2 | ? | ? | ? | ? | ? | ? | ? | ? | 0.13 - 0.15.1 | 0.13 - 0.18 | × | × | × | × | × | × | × | × | × | × | × | × | × | × | × | × | × | × | × | | 7.2 | ? | ? | ? | ? | ? | ? | ? | ? | 0.13 - 0.15.1 | 0.13 - 0.18 | 0.14 - 0.18 | × | × | × | × | × | × | × | × | × | × | × | × | × | × | × | × | × | × | | 7.3 - 7.3.3 | ? | ? | ? | ? | ? | ? | ? | ? | 0.13 - 0.15.1 | 0.13 - 0.18 | 0.14 - 0.18 | 0.14 - 0.18 | × | × | × | × | × | × | × | × | × | × | × | × | × | × | × | × | × | | 7.4 - 7.4.2 | ? | ? | ? | ? | ? | ? | ? | ? | 0.14 - 0.15.1 | 0.14 - 0.18 | 0.14 - 0.18 | 0.14 - 0.18 | 0.15 - 0.18 | × | × | × | × | × | × | × | × | × | × | × | × | × | × | × | × | | 7.5 - 7.5.1 | ? | ? | ? | ? | ? | ? | ? | ? | 0.14 - 0.15.1 | 0.14 - 0.18 | 0.14 - 0.18 | 0.14 - 0.18 | 0.15 - 0.18 | 0.15 - 0.18 | × | × | × | × | × | × | × | × | × | × | × | × | × | × | × | 7.6 - 7.6.4 | ? | ? | ? | ? | ? | ? | ? | ? | 0.14 - 0.15.1 | 0.14 - 0.18 | 0.14 - 0.18 | 0.14 - 0.18 | 0.15 - 0.18 | 0.15 - 0.18 | × | × | × | × | × | × | × | × | × | × | × | × | × | × | × | | 8.0 - 8.1 | ? | ? | ? | ? | ? | ? | ? | ? | ? | ? | ? | ? | ? | 0.15 - 0.18 | 0.16 - 0.18 | 0.16 - 0.18 | × | × | × | × | × | × | × | × | × | × | × | × | × | | 8.2 - 8.3 | ? | ? | ? | ? | ? | ? | ? | ? | ? | ? | ? | ? | ? | 0.17 - 0.18 | 0.17 - 0.18 | 0.17 - 0.18 | 0.17 - ∞ | × | × | × | × | × | × | × | × | × | × | × | × | | 8.4 - 8.5 | ? | ? | ? | ? | ? | ? | ? | ? | ? | ? | ? | ? | ? | 0.17 - 0.18 | 0.17 - 0.18 | 0.17 - 0.18 | 0.17 - ∞ | 0.17 - ∞ | × | × | × | × | × | × | × | × | × | × | × | | 8.6 | ? | ? | ? | ? | ? | ? | ? | ? | ? | ? | ? | ? | ? | 0.17 - 0.18 | 0.17 - 0.18 | 0.17 - 0.18 | 0.17 - ∞ | 0.17 - ∞ | 0.17 - ∞ | × | × | × | × | × | × | × | × | × | × | | 8.7 - 8.8 | ? | ? | ? | ? | ? | ? | ? | ? | ? | ? | ? | ? | ? | 0.18 - 0.18 | 0.18 - 0.18 | 0.18 - 0.18 | 0.18 - ∞ | 0.18 - ∞ | 0.18 - ∞ | 0.18 - ∞ | 0.18 - ∞ | × | × | × | × | × | × | × | × | | 8.9 - 8.10.1 | ? | ? | ? | ? | ? | ? | ? | ? | ? | ? | ? | ? | ? | 0.18 - 0.18 | 0.18 - 0.18 | 0.18 - 0.18 | 0.18 - ∞ | 0.18 - ∞ | 0.18 - ∞ | 0.18 - ∞ | 0.18 - ∞ | 0.18 - ∞ | × | × | × | × | × | × | × | | 8.10.2 - 8.11 | ? | ? | ? | ? | ? | ? | ? | ? | ? | ? | ? | ? | ? | 0.18 - 0.18 | 0.18 - 0.18 | 0.18 - 0.18 | 0.18 - ∞ | 0.18 - ∞ | 0.18 - ∞ | 0.18 - ∞ | 0.18 - ∞ | 0.18 - ∞ | 0.18 - ∞ | × | × | × | × | × | × | | 8.11.1 - 8.12 | ? | ? | ? | ? | ? | ? | ? | ? | ? | ? | ? | ? | ? | 0.18 - 0.18 | 0.18 - 0.18 | 0.18 - 0.18 | 0.18 - ∞ | 0.18 - ∞ | 0.18 - ∞ | 0.18 - ∞ | 0.18 - ∞ | 0.18 - ∞ | 0.18 - ∞ | 0.18 - ∞ | 0.19 - ∞ | × | × | × | × | | 8.13 | ? | ? | ? | ? | ? | ? | ? | ? | ? | ? | ? | ? | ? | 0.18 - 0.18 | 0.18 - 0.18 | 0.18 - 0.18 | 0.18 - ∞ | 0.18 - ∞ | 0.18 - ∞ | 0.18 - ∞ | 0.18 - ∞ | 0.18 - ∞ | 0.18 - ∞ | 0.18 - ∞ | 0.19 - ∞ | 0.19 - ∞ | 0.19 - ∞ | 0.19 - ∞ | × | | 8.14 - 8.14.3 | ? | ? | ? | ? | ? | ? | ? | ? | ? | ? | ? | ? | ? | ? | ? | ? | 0.19 - ∞ | 0.19 - ∞ | 0.19 - ∞ | 0.19 - ∞ | 0.19 - ∞ | 0.19 - ∞ | 0.19 - ∞ | 0.19 - ∞ | 0.19 - ∞ | 0.19 - ∞ | 0.19 - ∞ | 0.19 - ∞ | × | | 9.0.0 | ? | ? | ? | ? | ? | ? | ? | ? | ? | ? | ? | ? | ? | ? | ? | ? | ? | ? | ? | ? | ? | ? | ? | ? | ? | ? | ? | 0.19 - ∞ | × | | 9.1.0 | ? | ? | ? | ? | ? | ? | ? | ? | ? | ? | ? | ? | ? | ? | ? | ? | ? | ? | ? | ? | ? | ? | ? | ? | ? | ? | ? | ? | 0.19 - ∞ | | 9.2.0 - 9.3.1 | ? | ? | ? | ? | ? | ? | ? | ? | ? | ? | ? | ? | ? | ? | ? | ? | ? | ? | ? | ? | ? | ? | ? | ? | ? | ? | ? | ? | 0.19 - ∞ | * ? = 不确定 AGP 是否支持,从未测试过。 * × = 基于 AGP 兼容性不兼容。 * sup. = 基于 AGP 兼容性支持,但未测试。 * N/A = 尚未提供完整支持,仅基于 AGP 的 alpha/beta 版本提供初步支持。 * ∞ = 最新版本 * ^1 = AGP 3.2 的 Gradle 4.4 — 4.9 从未被支持,因为很难回溯移植 lazy task configuration API。 * ^2 = Convention 插件仅支持 Gradle 6.1.1+ 上的 AGP 4.0.0 — 4.2.2,因为将所有功能回溯移植到 3.x 非常困难且无此必要。 * ^3 = 版本 0.16 放弃了对 Gradle 5.x — 7.x 上 AGP 3.x — 4.x 的支持,以使此项目更易于维护。 * ^4 = 版本 0.19 放弃了对 Gradle 7.x 上 AGP 7.x 的支持(由于 Kotlin 1.4 兼容性),AGP 8.0(由于 SDK 35 兼容性),Gradle 8.0-8.1(由于 configuration cache)。这应该能使此项目更易于维护。 ## 快速设置 使用 Gradle 插件有多种方式,请在下方选择适合你的方式。
现代 build.gradle(.kts) (plugins) ``` plugins { id("net.twisterrob.gradle.plugin.quality") version "x.y" } ```
常规 build.gradle(.kts) (buildscript) ``` buildscript { repositories { mavenCentral() } dependencies { classpath("net.twisterrob.gradle:twister-quality:x.y") } } // Kotlin apply(plugin = "net.twisterrob.gradle.plugin.quality") // Groovy apply plugin: "net.twisterrob.gradle.plugin.quality" ```
buildSrc classpath #### buildSrc/build.gradle(.kts) ``` repositories { mavenCentral() } dependencies { implementation("net.twisterrob.gradle:twister-quality:x.y") } ``` #### build.gradle(.kts) ``` // Kotlin apply(plugin = "net.twisterrob.gradle.plugin.quality") // Groovy apply plugin: "net.twisterrob.gradle.plugin.quality" ```
更多信息,请参阅 [examples](docs/examples) 文件夹。 ## 功能 ### HTML 违规报告 内置的 HTML 报告将所有模块的所有结果汇总到一个 HTML 文件中。 ``` gradlew :violationReportHtml ``` ### 控制台违规报告 内置的控制台报告将所有模块的所有结果汇总并输出结果到控制台。 ``` gradlew :violationReportConsole ``` ### 将违规计数报告写入文件 仅将违规数量保存到文件中。适合自动化。 ``` gradlew :violationCountFile ``` ### 出现违规时使构建失败 如果有违规就会失败。 ``` gradlew :validateViolations ``` ### 根项目测试报告 收集子模块的结果,如果有错误则失败。 ``` gradlew :testReport ``` 注意:这会将 `:*:test` 测试任务更改为不失败,以便生成涵盖整个项目的报告。 ### 全局终结器 `:lint` 任务 依赖于所有其他 lint 并显示失败摘要,以减少滚动/扫描构建日志的需要。 如果显式调用为 `gradlew :lint`,它将失败;否则(例如 `gradlew lint`),它只会静默地将其添加到 lint 任务列表中,并在最后打印摘要。 禁用方法: ``` afterEvaluate { tasks.named("lint").configure { it.enabled = false } } ``` ## 贡献,自定义构建 有关如何设置此项目,请参阅 [development.md](docs/development.md)。
标签:AGP, Android, Android Flavors, Android Lint, Checkstyle, DSL, Gradle, Groovy, Kotlin DSL, PMD, SOC Prime, 代码规范, 后台面板检测, 安全专业人员, 实时流处理, 开发工具, 插件, 漏洞测试, 移动开发, 错误基检测, 静态代码分析