Define global variables and functions in build.gradle

Is there a way to define global variables in build.gradle and make them accessible externally.

I mean something like this

 def variable = new Variable() def method(Project proj) { def value = variable.value } 

Because it tells me that it cannot find property . I would also like to do the same for methods. I mean something like this

 def methodA() {} def methodB() { methodA() } 
+7
groovy gradle
source share
1 answer

Use advanced properties.

 ext.propA = 'propAValue' ext.propB = propA println "$propA, $propB" def PrintAllProps(){ def propC = propA println "$propA, $propB, $propC" } task(runmethod) << { PrintAllProps() } 

Running runmethod fingerprints:

 gradle runmethod propAValue, propAValue :runmethod propAValue, propAValue, propAValue 

Learn more about Gradle. Additional properties here.

You should be able to call functions from functions without doing anything special:

 def PrintMoreProps(){ print 'More Props: ' PrintAllProps() } 

leads to:

 More Props: propAValue, propAValue, propAValue 
+7
source share

All Articles