0

我想在 bootstrap.groovy 的不同区域使用部分代码。我如何“包含”这些部分并重用它?

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

1 回答 1

0

您只需导入文件并调用函数或实例化其中定义的类

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()
        }
    }
}
于 2010-05-17T11:13:12.907 回答