androidgradleandroid-gradle-plugin

Print the plugin version gradle consumes with a conv


I have a convention plugin tv.twitch.gradle.plugins.android-library that defines all of our android {} defaults. It naturally depends on com.android.library: tv.twitch.gradle.plugins.android-library.build.kts:

plugins {
    ...
    id("com.android.library")
    ...
}

android {
    ...
}

We have a similar convention plugin for com.android.application.

We define the version for com.android.application in our lib.versions.toml:

[versions]
...
agp = "8.5.2"
...
[plugins]
android-application = { id = "com.android.application", version.ref = "agp" }
...

I just noticed that we don’t define a version for com.android.library anywhere. How can I find its version?

I tried using the buildEnvironment task:

classpath
+--- com.android.test:com.android.test.gradle.plugin:8.5.2
...
+--- tv.twitch.gradle.plugins.android-app:tv.twitch.gradle.plugins.android-app.gradle.plugin:1.13
|    \--- tv.twitch:plugins:1.13
|         +--- org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.23 -> 1.9.25 (*)
|         +--- com.android.tools.build:gradle:8.5.2 (*)
|         +--- org.jlleitschuh.gradle:ktlint-gradle:12.1.1
|         +--- org.gradle.android.cache-fix:org.gradle.android.cache-fix.gradle.plugin:3.0
|         |    \--- gradle.plugin.org.gradle.android:android-cache-fix-gradle-plugin:3.0
|         |         \--- com.google.guava:guava:32.1.3-jre (*)
|         +--- org.barfuin.texttree:text-tree:2.1.2 (*)
|         \--- org.jetbrains.kotlinx:kover:0.6.1
+--- tv.twitch.gradle.plugins.android-library:tv.twitch.gradle.plugins.android-library.gradle.plugin:1.13
|    \--- tv.twitch:plugins:1.13 (*)

And this makes sense because we these are the dependencies we declare in the dependencies {} of the tv.twitch:plugins project. How do I resolve the version of com.android.library that tv.twitch.gradle.plugins.android-library:tv.twitch.gradle.plugins.android-library.gradle.plugin will consume?


Solution

  • It is the same version as the one for com.android.application.

    com.android.library and com.android.application are two plugins that live in the same code artifact, that is the Android Gradle plugin.

    If you use those IDs in a plugins { ... } block, they are by naming convention translated to the plugin marker artifacts <plugin id>:<plugin id>.gradle.plugin:<plugin version>.

    The plugin marker artifacts usually do not have an artifact but just depend on the code artifact where those plugins live. So in case of the two Android plugins those marker artifacts are both pointing to the Android Gradle Plugin artifact which you also see in your buildEnvironment output.