如何从我自己的Gradle插件中确定正在使用的Android Gradle插件版本?

时间:2022-03-18 07:00:16

Context

I'm writing a Gradle plugin for Android projects. My plugin relies on some methods from the Android Gradle plugin, but the exact calls I need to use have changed as the Android Gradle plugin has evolved (e.g. the methods I need are different in v2.1.2 vs v2.2.2 of the Android Gradle plugin). I want to get the Android Gradle plugin version programmatically from within my own plugin, and then invoke the appropriate methods for that version.

我正在为Android项目编写Gradle插件。我的插件依赖于Android Gradle插件中的一些方法,但我需要使用的确切调用随着Android Gradle插件的发展而改变(例如我需要的方法在Android Gradle插件的v2.1.2 vs v2.2.2中有所不同)。我想从我自己的插件中以编程方式获取Android Gradle插件版本,然后为该版本调用适当的方法。

Question

How can I access the Android Gradle plugin version programmatically from within my own Gradle plugin? Is calling

如何从我自己的Gradle插件中以编程方式访问Android Gradle插件版本?正在打电话

project.rootProject.buildscript.getDependencies()

the right starting point?

正确的起点?

1 个解决方案

#1


-1  

You can obtain a Gradle instance by calling Project.getGradle(), then invoke gradle.gradleVersion to get the current Gradle version!

您可以通过调用Project.getGradle()获取Gradle实例,然后调用gradle.gradleVersion以获取当前的Gradle版本!

Maybe it can help you!

也许它可以帮到你!

#1


-1  

You can obtain a Gradle instance by calling Project.getGradle(), then invoke gradle.gradleVersion to get the current Gradle version!

您可以通过调用Project.getGradle()获取Gradle实例,然后调用gradle.gradleVersion以获取当前的Gradle版本!

Maybe it can help you!

也许它可以帮到你!