gradle / gradle

Adaptable, fast automation for all
https://gradle.org
Apache License 2.0
16.65k stars 4.66k forks source link

resolutionStrategy in pluginManagement is not working for plugins with multivariants #20545

Open Tapchicoma opened 2 years ago

Tapchicoma commented 2 years ago

Expected Behavior

I could use following approach in settings.gradle for plugin published with Gradle variants:

pluginManagement {
        resolutionStrategy {
            eachPlugin {
                when (requested.id.id) {
                    "org.jetbrains.kotlin.platform.js" -> useModule("org.jetbrains.kotlin:kotlin-gradle-plugin:<some_version>")
                }
            }
        }
}

Gradle is working correctly If plugin is published without variants.

Current Behavior

Gradle fails with following message:

Plugin [id: 'org.jetbrains.kotlin.platform.js', artifact: 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.255-SNAPSHOT'] was not found in any of the following sources:

Context

Users could not access Gradle plugins, whose markers are not published to the Gradle plugin portal, but plugin uses Gradle plugin variants feature. This is affecting Kotlin 1.7.0+ versions as well.

Steps to Reproduce

repositories { mavenLocal() mavenCentral() }

Tapchicoma commented 2 years ago

Workaround is to use buildscript.dependencies { classpath ... } } approach

ljacomet commented 2 years ago

Your reproducer mentions adding repositories to the project, but these will not impact where the plugin is searched for. As you removed the searched locations from your error, can you double check that if you declare the repositories in settings it works?

Tapchicoma commented 2 years ago

missed in the code snippet, just add following repositories into pluginManagement block in settings.gradle.kts:

repositories {
    mavenLocal()
    gradlePluginPortal()
}
BoD commented 2 years ago

Hi! Facing a similar issue when trying to use useModule with the Kotlin plugin 1.7-Beta, but I don't understand the suggested workaround.

ov7a commented 10 months ago

Sorry for the late reply.

Thank you for providing a valid report.

The issue is in the backlog of the relevant team, but the existence of a workaround makes it non-critical, so it might take a while before a fix is made.