How to find gradle plugin id for given gradle library?
Asked Answered
R

4

6

I am currently updating my project and as one of the steps I am changing gradle files to use the plugins { id 'xxx' } way instead of the legacy apply plugin 'xxx' approach. I was able to migrate most of the imports to the new format, however I cannot add some plugins, as I am unable to find their gradle plugin ids.

For example, here are my old gradle files:

settings.gradle file

include ':app'

project's build.gradle file

buildscript {
    repositories {
        google()
        mavenCentral()
        (...)
    }
    dependencies {
        (...)
        classpath 'com.google.firebase:firebase-crashlytics-gradle:2.9.0'
        classpath 'com.google.android.gms:oss-licenses-plugin:0.10.5'
    }
}
(...)

module's build.gradle file

apply plugin: 'com.android.application'
apply plugin: 'com.google.firebase.crashlytics'
apply plugin: 'com.google.android.gms.oss-licenses-plugin'
(...)

And here are partially modified new gradle files:

settings.gradle file

pluginManagement {
    repositories {
        gradlePluginPortal()
        google()
        mavenCentral()
    }
}
dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {
        google()
        mavenCentral()
    }
}
rootProject.name = "xxxx"
include ':app'

project's build.gradle file

plugins {
    id 'com.android.application' version '7.3.1' apply false
    id 'com.google.firebase.crashlytics' version '2.9.2' apply false
    // DOESN'T WORK:
    id 'com.google.android.gms.oss-licenses-plugin' version '0.10.5' apply false
}
(...)

module's build.gradle file

plugins {
    id 'com.android.application'
    id 'com.google.firebase.crashlytics'
    // NEED TO SET SAME ID AS IN PROJECT'S GRADLE FILE PROBABLY:
    id 'com.google.android.gms.oss-licenses-plugin'
    (...)
}

Problem lays in how to get gradle plugin id for given plugin? Many plugin installation instructions use the old apply plugin approach and I don't want to mix both of them.

For example in case of Crashlytics with classpath of com.google.firebase:firebase-crashlytics-gradle, the id is com.google.firebase.crashlytics - how was I supposed to know that? I found this in one of the answers on Stackoverflow, but without information about how someone knew that.

Currently I am trying to add the oss-licenses-plugin and I am completly clueless as about how to find its gradle plugin id... Any suggestions?

Or maybe it is not guaranteed that every plugin added with use of classpath can be translated to the new plugins { } way? In this case, how can I tell it is this situation?

Russophobe answered 27/10, 2022 at 12:0 Comment(2)
I have researched a little bit and in the case of crashlytics, the path is the same as the directory structure if you download the jar file and you extract it. Unfortunately, I have tried the same approach with com.google.android.gms.oss-licenses-pluginwhich should be converted to com.google.android.gms.oss.licenses.plugin according to the directory structure and it is not working.Enosis
Have com.google.android.gms.oss-licenses-pluginfollowing com.android.applicationprior to com.google.firebase.crashlytics - see whether that helps - otherwise I am just as stumpedReuven
L
10

There's a certain pattern that plugin publishers need to follow in order for Gradle to find the plugin implementation. A properties file needs to be included in the JAR's META-INF/gradle-plugins directory. And the name of this file needs to be formatted in the following way:

<plugin-id>.properties

And inside this file, the plugin implementation is defined:

implementation-class=<com.example.SomePluginImpl>

So, to answer your question, you'll need to get a hold of the JAR & look at its contents to figure out the id: META-INF/gradle-plugins/<plugin-id>.properties.

For com.google.android.gms.oss-licenses-plugin, I checked here: Link. Alternatively, you can grab the JAR from maven, extract its contents & check the properties file: Link.

The other issue with your code is that for external plugin resolution, you need to define a resolutionStrategy under pluginManagement:

pluginManagement {
    resolutionStrategy {
        eachPlugin {
            if (requested.id.id == 'com.google.android.gms.oss-licenses-plugin') {
                useModule "com.google.android.gms:oss-licenses-plugin:${requested.version}"
            }
        }
    }
    repositories {
        gradlePluginPortal()
        google()
        mavenCentral()
    }
}

Now you should be able to use id 'com.google.android.gms.oss-licenses-plugin' version '0.10.5' apply false in your project-level build.gradle.

Ligule answered 12/11, 2022 at 7:54 Comment(1)
Thank you for detailed answer! Well, is it just me or is it way too complicated in the current form? I hope it is just some transitional period and with time all plugins will be migrated to gradle repo, so there's no need for such workarounds.Russophobe
L
1

according to gradle docs, you can find the plugin registered in here

not all gradle plugin available, because the dev need to publish their plugin to gradle first, here how to publish the plugin https://plugins.gradle.org/docs/publish-plugin

edit : I tried to find oss-licenses-plugin, no luck with that. So you should use the old method to apply the plugin.

other info : What the difference in applying gradle plugin

Linin answered 9/11, 2022 at 16:33 Comment(0)
M
0

just click on the artifact in maven and observe this bit of the address:

  https://mvnrepository.com/artifact/

com.google.firebase.appdistribution

/com.google.firebase.appdistribution.gradle.plugin
Missile answered 16/5, 2024 at 11:29 Comment(0)
D
0

How to figure out the id of the nebula-ospackage plugin : https://github.com/nebula-plugins/gradle-ospackage-plugin this do not have src/main/META-INF/gradle-plugins

I am facing issue with building dependencies for gradle 8.10 and line in build.gradle apply plugin: "nebula.ospackage". plugin not foudn error.

I have tried alternative: plugins {

   id("com.netflix.nebula.ospackage") version "11.1.0"

}

ALso tried plugins {

  id("nebula.ospackage") version "11.1.0"

}

All these things still did not give results. Kindly suggest.

Deduce answered 30/8, 2024 at 9:45 Comment(2)
If you have a new question, please ask it by clicking the Ask Question button. Include a link to this question if it helps provide context. - From ReviewConflagration
it's not an answer, its another question...Dakar

© 2022 - 2025 — McMap. All rights reserved.