Gradle
$ gradle 官方出品 中风险Gradle(gradle / ./gradlew)通过 Groovy/Kotlin DSL 脚本与持久化构建缓存驱动 Java、Kotlin 与 Android 的增量构建。它支持 --console=plain、--dry-run(-m)、--offline 与 --no-daemon,适合稳定的无头 CI 与 Agent 工作流。
brew install gradle gradle 直接在本地执行增量 JVM/Android 编译、依赖解析与 JUnit 测试任务,无法通过 MCP 替代。
Agent 友好度体检单
当前为静态评估(本机尚未安装或尚未运行探针)。可在本地运行 npm run data:probe 并提交 data/probes/ 升级为实测证据。
FCRS-1.0 六维评分拆解
支持 --console=plain、--dry-run(-m)、--offline、--no-daemon 与 --quiet,但输出均为纯文本且无原生 --json。
--console=plainstrips dynamic progress bars and ANSI color codes--dry-runevaluates and prints the task graph without running actions
--dry-run 可安全检查任务依赖图,构建产物集中在 build/ 与 ~/.gradle/,但 build.gradle(.kts) 在配置阶段可执行任意 JVM 代码。
gradle <task> --dry-runvalidates task wiring before execution
可通过 Homebrew、SDKMAN 与项目内置 ./gradlew wrapper 在 macOS、Linux 与 Windows 运行,依赖兼容 JDK。
./gradlewpins exact Gradle version per repo, requires JDK
增量任务输出、构建缓存与配置缓存使重复编译和测试迭代显著快于 Maven。
- Incremental builds and build cache skip up-to-date tasks
Gradle Inc. 官方开源项目(gradle/gradle),Apache-2.0 协议。
- Maintained by Gradle Inc. (
gradle/gradle)
docs.gradle.org 提供详尽 CLI 文档,但 Groovy 与 Kotlin DSL 示例随版本有所差异。
- Official CLI reference at docs.gradle.org
安全边界、鉴权与放权指南
公共仓库无需认证;私有 Maven/Gradle 凭据保存在 ~/.gradle/gradle.properties 或环境变量中。
Apache-2.0 开源 CLI,免费使用(Develocity Build Scan 为可选项)。
# Gradle Agent Rules - Prefer `./gradlew` over global `gradle` when the wrapper exists in the repo. - Always pass `--console=plain` (and `--no-daemon` in ephemeral sandboxes) and preview task graphs with `--dry-run`.
Agent 高频安全命令配方
只读查询(安全推荐)
gradle test --dry-run --console=plain
解析任务依赖图并打印将执行的任务顺序(标记为 SKIPPED),不真正执行动作。
gradle tasks --console=plain
不渲染动态 ANSI 进度条地列出项目可运行任务。
受控写入与预演
gradle check --console=plain --no-daemon
在单次干净的 JVM 进程中执行编译与测试,不残留后台守护进程。
核心优势
- +
--console=plain消除会破坏 Agent 日志解析的动态终端进度条。 - +
--dry-run可在运行耗时构建前预览精确的任务 DAG。 - + 增量构建缓存与
./gradlewwrapper 确保构建既快又可复现。
注意事项与踩坑点
- ! 任务列表、依赖树与测试摘要均不支持原生
--json输出。 - ! 默认后台 Gradle daemon 在短生命周期沙箱中可能残留,需加
--no-daemon。