Including a groovy script in another groovy

前端 未结 12 1527
走了就别回头了
走了就别回头了 2020-11-27 12:07

I have read how to simply import a groovy file in another groovy script

I want to define common functions in one groovy file and call those functions from other groo

12条回答
  •  臣服心动
    2020-11-27 12:51

    How about treat the external script as a Java class? Based on this article: https://www.jmdawson.net/blog/2014/08/18/using-functions-from-one-groovy-script-in-another/

    getThing.groovy The external script

    def getThingList() {
        return ["thing","thin2","thing3"]
    }
    

    printThing.groovy The main script

    thing = new getThing()  // new the class which represents the external script
    println thing.getThingList()
    

    Result

    $ groovy printThing.groovy
    [thing, thin2, thing3]
    

提交回复
热议问题