最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Gradle Plugin, define repositories for internal dependencies - Stack Overflow

programmeradmin4浏览0评论

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?

发布评论

评论列表(0)

  1. 暂无评论