当前位置:首页>行业动态> 正文

Deprecated Gradle features were used in this build

当您在构建过程中看到 "Deprecated Gradle features were used in this build" 这样的警告时,这意味着您正在使用一些已经被弃用的 Gradle 功能,这些功能在未来的 Gradle 版本中可能会被移除或更改,因此建议您尽快更新您的构建脚本以避免潜在的问题。

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

1、插件依赖管理

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

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

2、任务依赖管理

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

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

Deprecated Gradle features were used in this build  第1张

3、属性文件的使用

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

替代方案:使用FileInputStreamProperties 类加载属性文件。

4、Groovy DSL 的使用

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

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

5、Gradle Wrapper 的使用

被弃用的功能:gradlew build

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

6、Gradle 1.0 插件 API

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

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

7、Gradle 2.0 插件 API

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

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