Deprecated Gradle features were used in this build
发布时间:2026-12-01 08:23:52

当(dang)您在构建(jian)过程中看(kan)到 "Deprecated Gradle features were used in this build" 这样的警告时(shi),这意味着您正在使用一些已经被弃用的 Gradle 功能,这些功能(neng)在未来的 Gradle 版本中可能会被移除或更改,因(yin)此建议您尽快更(geng)新您的构建(jian)脚本以避免潜在的(de)问题。(图片来源网络,侵删)

以下是一些常见的被弃用的 Gradle 功能及其替代方案:

Deprecated Gradle features were used in this build

1、插件依赖管理(li)

Deprecated Gradle features were used in this build

被弃用的功能:apply plugin: 'x'

Deprecated Gradle features were used in this build

替代方案:使用 plugins { id 'x' } 替换 apply plugin: 'x'。

2、任(ren)务依赖管理

被弃用的功能:task x << { ... }

替代方案:使用 doLast { ... } 替换 << { ... }。

3、属性文件的使用

被弃用的功能:Properties prop = new Properties()

替代方(fang)案:使用 FileInputStream 和 Properties 类加载属性文件(jian)。

4、Groovy DSL 的使用

被弃用的功能:project.with { ... }

替代方案:使用 project.configure(it) 替换 with。

5、Gradle Wrapper 的使用

被弃用(yong)的功能:gradlew build

替代方案:确保项目中包含一个有效的 Gradle Wrapper(位于 gradle/wrapper/gradlewrapper.properties),然(ran)后使(shi)用 ./gradlew build 运行(xing)构建。

6、Gradle 1.0 插件 API

被弃用的功能:project.getGradle().addListener(new MyGradleListener())

替代方案:使用(yong) project.getGradle().addListener(new MyGradleListener())。

7、Gradle 2.0 插件 API

被弃用的功能:project.getPluginManager().withPlugin('x') { ... }

替代方案:使用 project.getPluginManager().withPlugin('x') { ... }。