Global application of community plugins


(nick.mcavoy) #1

We have a global.gradle file in the Gradle user home that all projects apply from. Among other things it applies the java, eclipse, and maven-publish plugins. I’d also like to be able to use it for community plugins, for instance the release plugin. I haven’t been able to figure out how.

Plugins blocks can’t be sourced from another file; using a buildscript block in global.gradle would solve half the problem except it doesn’t seem to affect the classpath of the including file; the settings.gradle. pluginRepositories route doesn’t seem to do the trick either.

Am I missing a way to do this? I’ve looked around the documentation for plugins, init scripts, release 2.14, settings, and so on without much luck.

(Stefan Oehme) #2

I find the idea of using apply from: together with a machine-local file questionable. This means the projects won’t build for anyone else checking them out.

If that is really what you want, use an init script instead. There you can use the allProjects block, which also allows you to add things to the buildscript block of each individual project.

allprojects {
  buildscript {
    // get some community plugin
  apply plugin: 'id-of-community-plugin'

At some point there will be an equivalent way of doing this with the new plugins syntax, but it does not exist yet.

(nick.mcavoy) #3

This is a much-belated reply, but thanks! I think the init.gradle does what we need.

(nick.mcavoy) #4

Except, can you confirm that this works? In my init.gradle:

allprojects { project ->
  buildscript {
    repositories {
      maven {
        url ""
    dependencies {
      classpath ""
  apply plugin: "com.github.mgk.gradle.s3"

Then, from another project:

> gradle tasks

FAILURE: Build failed with an exception.

* Where:
Initialization script '/home/nick/projects/IDMP/Gradle/init.d/init.gradle' line: 12

* What went wrong:
Plugin with id 'com.github.mgk.gradle.s3' not found.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.