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:
- BintrayJCenter
- maven(https://maven.fabric.io/public)
- Gradle Central Plugin Repository
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?
Run Android Studio. From the menu bar, select Android Studio > Preferences. Under IDE Settings, click Plugins and then click Install plugin from disk. Navigate to the folder where you downloaded the plugin and double-click it.
The plugins DSL provides a succinct and convenient way to declare plugin dependencies. It works with the Gradle plugin portal to provide easy access to both core and community plugins. The plugins DSL block configures an instance of PluginDependenciesSpec. To apply a core plugin, the short name can be used: Example 1.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With