When to use gradle.properties vs. settings.gradle?

ams picture ams · Jul 29, 2017 · Viewed 41k times · Source

A gradle build has three files

  • build.gradle that defines the build configuration scripts
  • gradle.properties
  • settings.gradle

Questions

  • What are differences between settings.gradle & gradle.properties?
  • When should a settings be put in settings.gradle vs. gradle.properties?

Answer

Lukas Körfer picture Lukas Körfer · Jul 29, 2017

settings.gradle

The settings.gradle file is a Groovy script, just like the build.gradle file. Only one settings.gradle script will be executed in each build (in comparison to multiple build.gradle scripts in multi-project builds). The settings.gradle script will be executed before any build.gradle script and even before the Project instances are created. Therefore, it is evaluated against a Settings object. With this Settings object you can add subprojects to your build, modify the parameters from the command line (StartParameter), and access the Gradle object to register lifecycle handlers. As a consequence, use settings.gradle if your settings are build-related and not necessarily project-related or require logic before possible subprojects are included.

gradle.properties

The gradle.properties file is a simple Java Properties file that only gains a special role by being automatically included into the scope of the Project object (as so-called 'project properties'). It's a simple key-value store that only allows string values (so you need to split lists or arrays by yourself). You can put gradle.properties files to these locations:

  • directly in the project directory (for project-related values)
  • in the user home .gradle directory (for user- or environment-related values)