6
votes

I have a project configured through the triple of:

  • Declare repository in top-level build.gradle:

    buildscript { repositories { google() }}
    allprojects { repositories { google() }}
    
  • Declare classpath dependency, so plugin artifact gets downloaded from the appropriate repository, in top-level build.gradle

    buildscript { dependencies { classpath 'com.android.tools.build:gradle:3.1.3' }}
    
  • Then, in the app build.gradle file, apply the plugin:

    apply plugin: 'com.android.application'
    

I want to migrate this to use the new plugins DSL as enabled by the PluginsDependenciesSpec.

I then:

  • Declared the repository in settings.gradle:

    pluginManagement { repositories { google() }}
    
  • Declared the plugin dependency in the app build.gradle:

    plugins { id "com.android.application" version "3.1.3" }
    

But this fails to resolve:

FAILURE: Build failed with an exception.

  • Where: Build file '…/build.gradle' line: 2

  • What went wrong: Plugin [id: 'com.android.application', version: '3.1.3'] 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.android.library:com.android.library.gradle.plugin:3.1.3')

Searched in the following repositories:

What am I missing to get Gradle to connect the dots here, so that it can connect the plugin.id to the appropriate JAR fetched from the appropriate repository?

1

1 Answers

0
votes

Within the pluginManagement you can use resolutionStrategy and force usage of specific artifact from the google() repository.

pluginManagement {
    repositories {
        google()
    }

    resolutionStrategy {
        eachPlugin {
            if (requested.id.id in ['com.android.application', 'com.android.library']) {
                useModule("com.android.tools.build:gradle:${getProperty('version.plugin.android')}")
            }
        }
    }
}

Then you can apply android plugins with using new plugins DSL:

plugins {
    id 'com.android.application'
}

or

plugins {
    id 'com.android.library'
}

Here is the documentation.