Convert groovy script into gradle tasks

(andypdo) #1

Convert groovy into gradle task: I have the following groovy script, I would like to convert it into gradle, please help: def copyAndReplaceText(source, dest, Closure replaceText){

dest.write(replaceText(source.text)) }

def cli = new CliBuilder() cli.with {

h(longOpt: ‘help’, ‘Help - Usage Information’)

r(longOpt: ‘build-date’, ‘BuildDate’, type: String, args: 1, required: true)

t(longOpt: ‘template’, ‘template’, type: String, args: 1, required: true) } def opt = cli.parse(args) if (!opt) return if (opt.h)cli.usage() def rlsDate = new File(opt.r) def rlsVersion = new File(“1.” + “$rlsDate”) def sFile = new File(opt.t) //def src = new File("…/template/nuspec.template") def src = new File("_template/nuspec.template") //def dest = new File("$sFile" + “.nuspec”) def dest = new File("$sFile" + “/” + “$sFile” + “.nuspec”)

copyAndReplaceText (src, dest) {

it.replaceAll(“VERSION”, “$rlsVersion”).replaceAll(“ID”, “$sFile”).replaceAll(“TITLE”, “$sFile”).replaceAll(“SUMMARY”, “$sFile”).replaceAll(“DESC”, “$sFile”) }