Multiproject gradle seems to need plugin repository declared in each subproject

Hi,

my root gradle project defines a proxy for jcenter and the plugins repo but I seem to need to do this for every sub project as well. This violates Don’t-Repeat-Yourself so I must be approaching this incorrectly

buildscript {
repositories {
    maven {
        url "${ARTIFACTORY_CONTEXT_URL}/jcenter"
    }
    maven {
        url "${ARTIFACTORY_CONTEXT_URL}/maven-plugins-gradle-remote"
    }
}

What’s the right way to ensure all projects buildscript clause has the two definition?

Thanks

allprojects {
   buildscript {
      repositories { ... }
   } 
} 

Oh, that works. I was following Peter N’s answr and applying an additional script.

But only if I didn’t also need a buildscript clause for a specific project. I guess, I’d exclude it and then include it elsewhere

Please don’t use buildscript {} in subprojects. Simply declare all your plugin dependencies in the root project. This will give you much better performance because less classloaders will need to be created. It also avoids confusing situations where the root project already loaded a plugin and a child tries to request a different version, but gets the one loaded by the root. I plan to deprecate buildscript {} in subprojects for these reasons.

4 Likes