Gradle8.6发布

学学看科技 2024-02-07 16:51:19

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 改进

允许用户轻松创建新的 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 集成改进

集成到许多 IDE 中。

此外,Gradle 8.6 中还修复了 86 个 issue。更多详情可。

0 阅读:10

学学看科技

简介:感谢大家的关注