Groovy: import and use functions from another file

Code reuse is an important part of programming. The smallest possible way is to create functions and call them
several times in the same code. The next step is to have a set of functions in a file and use those functions in
several other files.

In this example we see how to do that with simple functions.

Importing function

In this example we have a very simple "library" file with a simple function:

examples/groovy/function_tools.gvy

def greet() {
println "Hello World!"
}

Next to it there is another file in which we load the former file into memory and then call it.

Comments

Author: Gabor Szabo

Gabor who runs the Code Maven site helps companies set up test automation, CI/CD
Continuous Integration and Continuous Deployment and other DevOps related
systems. Gabor can help your team improve the development speed and reduce the risk of bugs.