google / play-services-plugins

Plugins to help with using Google Play services SDK.
https://developers.google.com/android/guides/overview
Apache License 2.0
471 stars 138 forks source link

new gradle `pluginManagement` do not find plugin `com.google.gms.google-services` #207

Closed danielesegato closed 2 years ago

danielesegato commented 3 years ago

Following the new instructions to add google-services to my Android project I get this error:

org.gradle.internal.exceptions.LocationAwareException: Build file '.../app/build.gradle.kts' line: 1
Plugin [id: 'com.google.gms.google-services', version: '4.3.10'] was not found in any of the following sources:

- Gradle Core Plugins (plugin is not in 'org.gradle' namespace)
- Plugin Repositories (could not resolve plugin artifact 'com.google.gms.google-services:com.google.gms.google-services.gradle.plugin:4.3.10')
  Searched in the following repositories:
    Gradle Central Plugin Repository
    Google
    MavenRepo

As per instruction my settings.gradle.kts contains

pluginManagement {
  repositories {
    gradlePluginPortal()
    google()
    mavenCentral()
  }
  plugins {
    id("com.android.application") version "7.1.0-alpha13"
    id("com.android.library") version "7.1.0-alpha13"
    id("org.jetbrains.kotlin.android") version "1.5.21"
    id("com.google.gms.google-services") version "4.3.10" // <------
  }
}

while in my app/build.gradle.kts I've added:

plugins {
    id("com.android.application")
    kotlin("android")
    id("com.google.gms.google-services") // <-----
}

The instructions actually tells me to skip the declaration in the settings.gradle.kts and put the version directly in the app, I've tried that too, same result.

However, if I add in the root build.gradle.kts the legacy

buildscript {
  dependencies {
    classpath("com.google.gms:google-services:4.3.10")
  }
}

gradle can sync and it works as expected.

Isn't the new way supposed to replace the legacy one?

danielesegato commented 3 years ago

The issue is explained here https://github.com/square/wire/issues/1944

Apparently you forgot to publish the artifacts with the convention name and it isn't resolved.

the workaround is to add this inside the plugin management

pluginManagement {
    resolutionStrategy {
        eachPlugin {
            if (requested.id.id == "com.google.gms.google-services") {
                useModule("com.google.gms:google-services:4.3.10")
            }
        }
    }
}

Note that in the Wire issue they suggest to pass ${requested.version} in the useModule() but it gets resolved to null, failing, for me.

I had other plugins with the same issue so I used this syntax

    resolutionStrategy {
        eachPlugin {
            when (requested.id.id) {
                "com.google.gms.google-services" ->
                    useModule("com.google.gms:google-services:4.3.10")
                "com.google.firebase.crashlytics" ->
                    useModule("com.google.firebase:firebase-crashlytics-gradle:2.8.0")
                // etc.
            }
        }
    }
hvisser commented 3 years ago

The wire issue doesn't fully spell it out I suppose, but for the resolution to work the plugin marker artifact should be published to maven.google.com.

~Usually the java-gradle-plugin sets this up, but that plugin isn't used in this project, but it can probably be added to the publish.gradle script.~

If you encounter other plugins not supporting this, ask them to publish the marker artifact too so no work arounds are needed.

hvisser commented 3 years ago

The plugin descriptor is actually generated in the repo found in build/repo but it doesn't appear to be available on maven.google.com

image

plnice commented 3 years ago

Also reported here: https://github.com/google/play-services-plugins/issues/50

davidmotson commented 2 years ago

Hello, this should be resolved now, as the extra artifact is now released to gmaven.