Gradle set global property for all projects from gradle

I would like to set a property from gradle (e.g. from settings.gradle) in a way similar to gradle.properties or -D . Is it possible?

The following code demonstrates what I'm trying to do, but its not working:

 import org.gradle.internal.os.OperatingSystem def getArchitecture() { return System.getProperty("os.arch") } def getName() { if(OperatingSystem.current().isMacOsX()) { return "darwin" } else if(OperatingSystem.current().isLinux()) { return "linux" } else { throw Exception("The operating system you use is not supported.") } } allprojects { ext { // this variable has to be visible from all the projects // and .gradle files in the same way as if it was set // from gradle.properties file buildMachine = getName() + "_" + getArchitecture() } } 

Edit

I would like this property to be defined in settings.gradle and be visible in all other .gradle files

Edit2

I have several machines to build, and I don’t want to specify the value of the buildMachine variable (in the settings and in other .gradle files), and I would not want this to be passed using -P or using gradle.properties , because it seems possible to define this property only inside gradle

+4
source share

All Articles