Issue
I have groovy scripts that I currently use within Jenkinsfiles
across multiple projects. I would like these same groovy scripts to be executable within gradle tasks in build.gradle
files across a few different projects as well. What is the easiest way to go about this? How can groovy functions be invoked within gradle tasks? Would it be best to wrap the code in something like a gradle plugin so it is commonly available across different projects?
Solution
as a variant
file with groovy functions ccc/DDD.groovy
def greet(name){
println "hello $name"
}
gradle:
def groovyShell = new GroovyShell()
def ddd = groovyShell.parse( new File("ccc/DDD.groovy") )
task test{
doLast {
ddd.greet("world")
}
}
Answered By - daggett