Gradle 8.5 现已发布。Gradle 是一个基于 Apache Ant 和 Apache Maven 概念的项目自动化构建工具,支持依赖管理和多项目,类似 Maven,但比之简单轻便。它使用一种基于 Groovy 的特定领域语言来声明项目设置,而不是传统的 XML。
Gradle 现在支持在 Java 21 上运行。此版本对 Kotlin DSL 进行了改进,包括更快的 first use 以及预编译 Kotlin 脚本插件中的版本目录支持。此外还提供了更多有用的错误和告警消息、改进了 build init 和依赖项验证,以及为构建和插件作者提供的几个新 API。
完整的 Java 21 支持
Gradle 8.4 支持使用 Java 工具链编译和测试 Java 21,但还不支持在 Java 21 上运行 Gradle 本身。新版本发布后,Gradle 现在完全支持在 Java 21 上编译、测试和运行。
详情可参阅完整的兼容性文档。
Kotlin DSL 改进
与传统的 Groovy DSL 相比,Gradle 的 Kotlin DSL 在支持的 IDE 中提供了更好的编辑体验:自动完成、智能内容辅助、快速访问文档、源代码导航和上下文感知重构。
- 首次使用速度更快:首次使用 Gradle 版本时,Gradle 会比以前更快地开始编译构建逻辑。
- 预编译脚本中的版本目录 API:
versionCatalogs
扩展访问器现在可用于 Kotlin DSL 预编译脚本。
// buildSrc/src/main/kotlin/my-convention-plugin.gradle.kts
versionCatalogs // This is the extension now available
.named("libs")// Assumes there is a libs catalog, throws exception otherwise
.findLibrary("assertj-core")// Search the catalog for an assertj-core entry
.ifPresent { assertjCore -> // If there is one ...
dependencies {// ... Add a dependency to it
testImplementation(assertjCore)
}
}
- 能够为脚本编译启用 Kotlin 元数据版本检查
错误和告警报告改进
- 改进了使用 reserved names 创建配置时的弃用消息。弃用警告示例:
Configure project : The configuration customCompileOnly was created explicitly. This configuration name is reserved for creation by Gradle. This behavior has been deprecated. This behavior is scheduled to be removed in Gradle 9.0. Do not create a configuration with the name customCompileOnly. Consult the upgrading guide for further information: https://docs.gradle.org/8.5/userguide/upgrading_version_8.html#configurations_allowed_usage When creating configurations during sourceSet custom setup, Gradle found that configuration customCompileOnly already exists with permitted usage(s): Consumable - this configuration can be selected by another project as a dependency Resolvable - this configuration can be resolved by this project to a set of files Declarable - this configuration can have dependencies added to it Yet Gradle expected to create it with the usage(s): Declarable - this configuration can have dependencies added to it Gradle will mutate the usage of configuration customCompileOnly to match the expected usage. This may cause unexpected behavior. Creating configurations with reserved names has been deprecated. This will fail with an error in Gradle 9.0. Create source set custom prior to creating or accessing the configurations associated with it. For more information, please refer to https://docs.gradle.org/8.5/userguide/building_java_projects.html#sec:implicit_sourceset_configurations in the Gradle documentation.
- 改进了运行测试时对封装断言错误的处理
- 无法删除文件时提供更好的诊断:当 Gradle 无法删除文件时,它现在将提供扩展诊断。这有助于解决锁定文件、并发写入等问题。
更多详情可查看发布公告。