Is there a way to define global variables in build.gradle
and make them accessible from everywhere.
I mean something like this
def variable = new Variable() def method(Project proj) { def value = variable.value }
Because that way it tells me that it cannot find property
. Also I'd like to do the same for the methods. I mean something like this
def methodA() {} def methodB() { methodA() }
Variables that are created outside of a function (as in all of the examples above) are known as global variables. Global variables can be used by everyone, both inside of functions and outside.
gradle. Gradle is a build system (open source) that is used to automate building, testing, deployment, etc. “build.
Use extra properties.
ext.propA = 'propAValue' ext.propB = propA println "$propA, $propB" def PrintAllProps(){ def propC = propA println "$propA, $propB, $propC" } task(runmethod) << { PrintAllProps() }
Running runmethod
prints:
gradle runmethod propAValue, propAValue :runmethod propAValue, propAValue, propAValue
Read more about Gradle Extra Properties here.
You should be able to call functions from functions without doing anything special:
def PrintMoreProps(){ print 'More Props: ' PrintAllProps() }
results in:
More Props: propAValue, propAValue, propAValue
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