How to share a common build.gradle via a repository?

There are two possibilities:

  1. Publish a build script to a web server, and include it with apply from: "http://path/to/script.gradle"

  2. Write a Gradle plugin, publish it as a Jar to a Maven or Ivy repository, and include it with:

    buildscript {
        repositories { .. }
        dependencies "mygroup:myplugin:1.0"
    }
    
    apply plugin: "myplugin"
    

The second option is more complicated, but also somewhat more powerful. For example, plugin Jars will be cached, whereas remote build scripts currently won’t. In general, I recommend to start with 1., and move to 2. if and once it becomes necessary. In the future, Gradle will likely offer a mechanism which combines the ease of use of 1. with the advantages of 2.

Leave a Comment