Koger
Koger

Reputation: 1923

How to find gradle plugin id for given gradle library?

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?

Upvotes: 6

Views: 4237

Answers (4)

Sowjanya Puppala
Sowjanya Puppala

Reputation: 1

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.

Upvotes: 0

hmac
hmac

Reputation: 343

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

Upvotes: 0

Vikram
Vikram

Reputation: 51581

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.

Upvotes: 10

flx_h
flx_h

Reputation: 11

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

Upvotes: 1

Related Questions