Global settings for a number of different projects

Hello,

Gradle newbie here, so I apologise if this is a daft question.

I have a number of different projects which are built by Gradle and I want to include in each a set of global settings - “repositories” and “sourceSets” definitions and some constants. What would be the best approach for achieving this, please?

Thanks.

There are several approaches.

I chose to use an init.gradle script that must be created at userhome/.gradle/init.gradle. This script is executed for all projects.

in this script you can do for instance :

allprojects {
          ext.foo='bar'
        repositories {
   ...
 }
}

You may also centralize your configuration in an other script available at an URL and in the init.gradle script you can do :

apply from: 'http://blablabla/myremotescript.gradle'

You could also pre-configure a gradle wrapper with an init script using the same technics

Thank you - will investigate.

The approaches mentioned by ‘sgalles’ are valid.

One thing to be wary of with init scripts though is that the can potentially lead to non portable scripts, as they live outside of the build scope. This may or may not be what you want.

The simplest solution is to use a script plugin, available over HTTP as ‘sgalles’ suggests.

There are other options though such as binary plugins. See this chapter of the userguide for more detail.