在另一个常规中包含一个groovy脚本 [英] Including a groovy script in another groovy

查看:420
本文介绍了在另一个常规中包含一个groovy脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已阅读如何简单导入在另一个groovy脚本中的groovy文件



我想在一个groovy文件中定义常用函数,并从其他groovy文件中调用这些函数。

据我所知,这将会像使用脚本语言一样使用Groovy,即我不需要类/对象。我正在尝试类似于可以在常规中完成的dsl。所有变量都将从Java中断言,我想在shell中执行groovy脚本。

这可能吗?可以有人提供一些例子。

解决方案

  evaluate(new File(../ tools /Tools.groovy))

将其放在脚本的顶部。这将带来一个groovy文件的内容(只需用你的groovy脚本替换双引号之间的文件名)。



我用一个令人惊讶的叫做 Tools.groovy。


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 groovy files.

I understand this would be using Groovy like a scripting language i.e, I dont need classes/objects. I am trying to something like dsl that can be done in groovy. All variables will be asserted from Java and I want to execute groovy script in a shell.

Is this possible at all ? Can someone provide some example.

解决方案

evaluate(new File("../tools/Tools.groovy"))

Put that at the top of your script. That will bring in the contents of a groovy file (just replace the file name between the double quotes with your groovy script).

I do this with a class surprisingly called "Tools.groovy".

这篇关于在另一个常规中包含一个groovy脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆