Tiago Nunes
02/08/2021, 6:33 PMplugins {
id "org.jetbrains.kotlin.android" version "$kotlin_version"
}
I love the fact that it doesn't require me to change the classpath in project-level build.gradle
...But, does it work for every plugin? If it does, how would I do this?
id "androidx.navigation.safeargs.kotlin" version "2.3.3"
(Plugin [id: 'androidx.navigation.safeargs.kotlin', version: '2.3.3'] was not found in any of the following sources:)Javier
02/08/2021, 6:34 PMgoogle()
repo?Kirill Grouchnikov
02/08/2021, 6:34 PMTiago Nunes
02/08/2021, 6:35 PMTiago Nunes
02/08/2021, 6:35 PMTiago Nunes
02/08/2021, 6:39 PMJavier
02/08/2021, 6:39 PMSearched in the following repositories
Tiago Nunes
02/08/2021, 6:39 PMKirill Grouchnikov
02/08/2021, 6:40 PMandroidx.navigation:navigation-safe-args-gradle-plugin
Javier
02/08/2021, 6:40 PMKirill Grouchnikov
02/08/2021, 6:40 PMJavier
02/08/2021, 6:40 PMJavier
02/08/2021, 6:40 PMKirill Grouchnikov
02/08/2021, 6:41 PMTiago Nunes
02/08/2021, 6:42 PMbuildscript.repositories
and in allprojects.repositories
Javier
02/08/2021, 6:42 PMKirill Grouchnikov
02/08/2021, 6:43 PMdependencies
blockTiago Nunes
02/08/2021, 6:43 PMid "androidx.navigation:navigation-safe-args-gradle-plugin" version "2.3.3"
Kirill Grouchnikov
02/08/2021, 6:43 PMTiago Nunes
02/08/2021, 6:43 PMTiago Nunes
02/08/2021, 6:44 PMTiago Nunes
02/08/2021, 6:45 PMclasspath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
when doing
plugins {
id "org.jetbrains.kotlin.android" version "$kotlin_version"
}
Kirill Grouchnikov
02/08/2021, 6:45 PMTiago Nunes
02/08/2021, 6:50 PMclasspath
line
Does it work for every plugin? How? Why not?Kirill Grouchnikov
02/08/2021, 6:59 PMVampire
02/08/2021, 7:10 PMTiago Nunes
02/08/2021, 7:11 PMVampire
02/08/2021, 7:18 PMplugins { ... }
blocks, by default this is just gradlePluginPortal()
.
The repositories that you define in your build scripts or build script buildscript
blocks are irrelevant for that.
If you apply a plugin like with plugins { id "androidx.navigation.safeargs.kotlin" version "2.3.3" }
, then it searches in the plugin repositories for an artifact at
androidx.navigation.safeargs.kotlin:androidx.navigation.safeargs.kotlin.gradle.plugin:2.3.3
(this is naming convention to be able to map id to artifact).
This so-called marker artifact then has a dependency on the actual artifact that you add to classpath
with the legacy way.
Each plugin that is deployed to the Gradle plugin portal does have this marker artifact so you can simply use the new syntax (that also has other advantages, especially if you use Kotlin DSL build scripts).
If you have plugins in other repositories like in google()
there the marker artifacts might be missing, but you can compensate that in the setting script by a manual mapping.
That would look something like
pluginManagement {
repositories {
gradlePluginPortal()
google()
}
resolutionStrategy {
eachPlugin {
when (target.id.id) {
"androidx.navigation.safeargs.kotlin" ->
useModule("androidx.navigation:navigation-safe-args-gradle-plugin:${target.version}")
}
}
}
}
This is in Kotlin DSL, but you should be able to translate it to Groovy DSL relatively easy.
This setup allow for the advantages of the plugins block, while there are the marker artifacts missing.Tiago Nunes
02/08/2021, 7:25 PMIan Lake
02/08/2021, 8:44 PMVampire
02/08/2021, 8:51 PMVampire
02/08/2021, 8:52 PMIan Lake
02/08/2021, 8:52 PM