I have very long include in settings.gradle:
include 'project-subproj1', 'project-subproj2', 'project-subproj3', 'project-subproj4'
What proper syntax to split long lines in settings.gradle?
I think about:
include 'project-subproj1', \
'project-subproj2', \
'project-subproj3', \
'project-subproj4'
but seems that
include 'project-subproj1',
'project-subproj2',
'project-subproj3',
'project-subproj4'
also works.
Is settings.gradle a regular Groovy script?
Is settings.gradle a regular Groovy script?
Yes, it is.
Just to explain a bit, Gradle reads the settings.gradle file and it actually creates an instance of Setting class.
If you see the include method spec on the Setting class it is like this:
void include(java.lang.String[] strings);
So the method accepts array of String class as argument. In groovy you can call this method in different ways:
include "project1", "project2"
include "project1",
"project2"
include (['project1',
'project2'] as String[])
include ('project1',
'project2')
Yes, in Gradle, each file that ends with .gradle is a regular Groovy script. Unscripted files in Gradle are indicated by other file extensions (e.g. .properties).
There are several conventions that define special groovy scripts:
build.gradle for the build configuration scriptsettings.gradle as build setup scriptinit.gradle in USER_HOME/.gradle/ for a global initialization scriptYou can create additional .gradle Groovy scripts and use them via apply from: or place them at special locations (e.g. USER_HOME/.gradle/init.d/ to use them as initialization scripts).
The main difference between all these scripts is the context they are applied on. All scripts first implement the Script interface and a second (role-specific) interface. The Gradle docs call this behaviour "attaching a delegate object".
build.gradle scripts are applied on a Project objectsettings.gradle scripts are applied on a Settings objectGradle objectNow, we can even understand the mentioned code example:
include 'project-subproj1',
'project-subproj2',
'project-subproj3',
'project-subproj4'
The Settings interface defines the include method, which is called in Groovy style: without brackets and across lines. You could also apply logic in your settings.gradle file, e.g. to require a condition before including a specific project.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With