I have been very frustrated by Gradle and variable scoping in a multi-module project. I have wasted countless hours trying to follow examples that simply do not work as stated, and having limited examples for the type of multi-module project that I wanted to create.
So first I started with a List variable at the outermost part of my build.gradle called versions:
The issue is that ‘def versions’ was not accessible in buildscript, allprojects, or subprojects scope.
Then I moved this variable to the ‘buildscript’ section:
Now buildscript has access to that variable, but allprojects and subprojects both cannot access this variable.
So by removing ‘def’ from versions like to have: versions = [root: "1.0.0"] versions was found by all scopes but now the next variable issue.
‘List list1′ and ‘List list2′ were both accessible to the buildscript but not to allprojects or subprojects.
So by removing the ‘List’ identifyer, finally all scopes had access to the variables I have set. Here is what I finally ended up with:
Which gave me this output:
I hope this can save someone else some frustration with variable scoping in a multi-module project.