Is there a way to inherit buildscript repositories in plugins?

I have written a plugin with a dependency from the jcenter() repository, like this:

repositories {
  mavenLocal()
  mavenCentral()
  jcenter()
}

Now I want to use this plugin in a project. It turns out that I have to include the jcenter() repository in the buildscript-part, although it is not needed anywhere else. Like this:

buildscript {
    repositories {
        mavenLocal()
        mavenCentral()
        maven {
            url uri('http://myLocalRepo/content/repositories/releases')
        }
        jcenter()
    }
    dependencies {
        classpath("com.mycompany:myPlugin:0.0.1-SNAPSHOT")
        }
}

Is it possible to “inherit” the jcenter()-repository from my plugin? I do not want to force anyone using my plugin to include jcenter().

Thanks for your help, Mo

I could be wrong, but as far as I know you can’t do this. I think the ‘buildscript’ block is evaluated very early in the lifecycle.

It’s not possible to “inherit” a repository. What you could do is define a virtual repository (e.g. ‘http://myLocalRepo/.../plugins’) that includes both ‘http://myLocalRepo/.../releases’ and ‘jCenter’. Artifactory supports this, and I assume also Nexus.

Thanks, Peter!