您现在的位置是:首页 > 文章详情

Gradle 8.6 发布

日期:2024-02-05点击:64

Gradle 8.6 现已发布。Gradle 是一个基于 Apache Ant 和 Apache Maven 概念的项目自动化构建工具,支持依赖管理和多项目,类似 Maven,但比之简单轻便。它使用一种基于 Groovy 的特定领域语言来声明项目设置,而不是传统的 XML。

此版本支持配置缓存的自定义加密密钥,对 build init 进行了多项改进,并更新了 build authoring API。还为 IDE integrators 提供了更多有用的错误和警告信息以及新的 API。

配置缓存改进

配置缓存通过缓存配置阶段的结果并将其重用于后续构建来缩短构建时间。此功能可以显着提高构建性能。

自定义加密密钥

配置缓存经过加密,可降低敏感数据意外泄露的风险。默认情况下,Gradle 会自动创建并管理密钥,并将其存储在 Gradle 用户主目录的密钥库中。这样做虽然方便,但在某些环境下可能并不合适。

现在用户可以向 Gradle 提供用于通过GRADLE_ENCRYPTION_KEY环境变量加密缓存配置数据的密钥。更多详细信息查看 Gradle 用户手册的配置缓存部分。

Build init 改进

build init 插件允许用户轻松创建新的 Gradle 构建,支持各种类型的项目。

Simpler source package handling

你不再需要回答有关源包的交互式问题。取而代之的是使用org.example的默认值。你可以使用init任务的现有选项--packageflag 来覆盖它。此外,还可以通过在 Gradle 用户主页的gradle.properties中添加org.gradle.buildinit.source.package新属性来设置默认值。

 // ~/.gradle/gradle.properties org.gradle.buildinit.source.package=my.corp.domain 

生成的 convention plugins 的名称现在以buildlogic开头,而不是软件包名称,从而使名称更简短、更整洁。

Generating without interactive questions

新增的 --use-defaults 选项可为未明确配置的选项应用默认值。它还能确保 init 命令在没有交互式用户输入的情况下完成。这在 shell 脚本中非常方便,可确保脚本不会意外挂起。

例如,你可以在不回答任何问题的情况下生成 Kotlin 库:

 gradle init --use-defaults --type kotlin-library 

Simpler assignment syntax in Kotlin DSL

示例:

 application { mainClass = "org.example.AppKt" }

Build authoring 改进

Gradle 为插件作者和构建工程师提供了丰富的 API 来开发自定义构建逻辑。如果执行构建不需要任务,则任务配置避免 API 会避免配置任务

Lazy name-based filtering of tasks

示例:

 tasks.named { it.contains("pack") }.configureEach { // lazily configure details of all '*pack*' tasks that are part of the task graph }

Allow Providers to be used with dependency capabilities

Gradle 支持声明组件的功能,以便允许 Gradle 在构建时检测和解决依赖项之间的冲突,从而更好地管理依赖项。

 dependencies { implementation("org.foo:bar:1.0") { capabilities { // Values in the interpolated String below are lazily evaluated, allowing them to be set after this block requireCapability(project.provider(() -> "${project.group}:${project.name}-platform:${project.version}")) } } } // Later, the version of the project is set. // Without the provider above, this change would not be reflected in the capability. project.version = "1.0.0" 

错误和警告报告改进

Gradle 提供了一组丰富的错误和警告消息来帮助用户理解和解决构建中的问题。

出现依赖锁定错误时更清晰的建议操作

此版本通过将错误与可能的操作分开以修复控制台输出中的问题,改进了依赖锁定中的错误消息。启用 strict mode 时,由于锁定文件格式无效或缺少锁定状态而导致的错误现在显示如下:

 FAILURE: Build failed with an exception. * What went wrong: Execution failed for task ':dependencies'. > Could not resolve all dependencies for configuration ':lockedConf'. > Invalid lock state for lock file specified in '<project>/lock.file'. Line: '<<<<<<< HEAD' * Try: > Verify the lockfile content. For more information on lock file format, please refer to https://docs.gradle.org/8.6/userguide/dependency_locking.html#lock_state_location_and_format in the Gradle documentation. > Run with --info or --debug option to get more log output. > Run with --scan to get full insights. > Get more help at https://help.gradle.org. 

更好地报告 providers 中的循环引用的错误

 FAILURE: Build failed with an exception. * Where: Build file '<project>/build.gradle' line: 7 * What went wrong: A problem occurred evaluating root project 'test'. > Circular evaluation detected: property(java.lang.String, map(java.lang.String map(<CIRCULAR REFERENCE>) check-type())) -> map(java.lang.String map(property(java.lang.String, <CIRCULAR REFERENCE>)) check-type()) -> map(property(java.lang.String, map(java.lang.String <CIRCULAR REFERENCE> check-type()))) -> property(java.lang.String, map(java.lang.String map(<CIRCULAR REFERENCE>) check-type())) 

IDE 集成改进

Gradle 使用 Tooling API 集成到许多 IDE 中。


此外,Gradle 8.6 中还修复了 86 个 issue。更多详情可查看官方公告

原文链接:https://www.oschina.net/news/277856/gradle-8-6-released
关注公众号

低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。

持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。

转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。

文章评论

共有0条评论来说两句吧...

文章二维码

扫描即可查看该文章

点击排行

推荐阅读

最新文章