Jeremy W. Sherman
Jeremy W. Sherman

Reputation: 36143

How to apply the com.android.application plugin using the new plugins DSL?

I have a project configured through the triple of:

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

I then:

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?

Upvotes: 6

Views: 1043

Answers (1)

franta kocourek
franta kocourek

Reputation: 1337

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.

Upvotes: 1

Related Questions