resolutionStrategy for external plugin resolution


(Sergey Malov) #1

Hi,
I’m having problems adding scalastyle plugin to my gradle build.
I’m defining it in plugin section as
id 'org.github.ngbinh.scalastyle' version "0.9.0"

Then, in settings.gradle I’m defining its resolution as

pluginManagement {
  resolutionStrategy {
    eachPlugin {
      if (requested.id.namespace == 'org.github.ngbinh.scalastyle') {
        useModule('org.github.ngbinh.scalastyle:gradle-scalastyle-plugin_2.11:0.9.0')
      }
    }
  }
  repositories {
    jcenter()
    gradlePluginPortal()
  }
}

As a result, I’m getting error:

Plugin Repositories (could not resolve plugin artifact
’org.github.ngbinh.scalastyle:org.github.ngbinh.scalastyle.gradle.plugin:0.9.0’)
Searched in the following repositories:
BintrayJCenter
Gradle Central Plugin Repository

Clearly, plugin with such id does not exist, it should try to resolve

‘org.github.ngbinh.scalastyle:gradle-scalastyle-plugin_2.11:0.9.0’

however, it does not, and I don’t understand how to make it.

Thank you,
Sergey Malov


(James Justinic) #2

You have multiple problems here. The first is that requested.id.namespace means the part before the last period. The namespace you have there would be org.github.ngbinh. If you are using the full id, it should be requested.id.id instead.

However, the plugin does not use a fully qualified name, so you would be forced to use apply false and then apply it manually. Instead, you can streamline things by using the same plugin id that the plugin declares, scalaStyle, and passing the requested version through.

// build.gradle
plugins {
    id 'scalaStyle' version '0.9.0'
}

// settings.gradle
pluginManagement {
    resolutionStrategy {
        eachPlugin {
            if (requested.id.id == 'scalaStyle') {
                useModule("org.github.ngbinh.scalastyle:gradle-scalastyle-plugin_2.11:${requested.version}")
            }
        }
    }     
} 

(Sergey Malov) #3

Nice, thank you!
Alternatively, I made it work adding buildscript{}, but I think this solution is a little more in tune with what scalastyle author had in mind.
Though it would be even better if he/she would add this plugin to central Gradle plugin repository …