views:

23

answers:

1

I want to use some parts of code in different area of bootstrap.groovy. How do I "include" these parts and reuse it?

def init = {
    environments {
        production {
            include("bla.groovy)
            include("blaFoo.groovy)
        }
        test {
            include("blaFoo.groovy)
        }
        development {
            include("bla.groovy)
            include("bla1.groovy)
            include("blaFoo.groovy)
        }
    }
}
A: 

You just import the files and call the functions or instantiate the classes defined therein

import bla
import blaFoo
import bla1

def init = {
    environments {
        production {
            // This function is defined in bla.groovy
            blaFunc()
        } test {
            // This class is defined in blaFoo.groovy
            new BlaFoo()
        } development {
            // This closure is defined in bla1.groovy
            bla1.call()
        }
    }
}
Don