I have two Gradle projects, one application and one Gradle plugin. The Gradle plugin applies multiple other plugins to a target project.
To do this I first include the other plugins as dependencies in the plugin project to get them on the classpath like so:
dependencies {
implementation(".jetbrains.kotlin:kotlin-gradle-plugin:2.1.20")
implementation(".jetbrains.kotlin.plugin.serialization:.jetbrains.kotlin.plugin.serialization.gradle.plugin:2.1.20")
}
Then I apply them to the target project in the plugin class:
class MyPlugin : Plugin<Project> {
override fun apply(target: Project) {
with(target) {
with(pluginManager) {
apply(".jetbrains.kotlin.multiplatform")
apply(".jetbrains.kotlin.plugin.serialization")
}
}
}
}
This has worked fine until I tried to also apply the Android application plugin (which exists in Google's maven repo and not Gradle's plugin repo):
dependencies {
implementation("com.android.application:com.android.application.gradle.plugin:8.9.1")
}
Gradle fails to find it even though I've defined the google()
repository in the plugin project's settings.gradle.kts
.
For some reason, Gradle is only looking for these dependencies in the Gradle plugin portal, regardless of what repositories I define.
I've found that it does work if I define the google()
repository in the target project like so:
pluginManagement {
repositories {
gradlePluginPortal()
google()
}
}
It doesn't make sense to me that the target project has to add a repository that the plugin uses to pull in internal dependencies.
Is there a way to tell the plugin project to look for these dependencies in the right repo without needing each consuming project to add google()
to their plugin repositories?