groovy - Whats the correct way to get Gradle to inform GroovyShell where the dependancies the script requires are? -
i've got gradle downloading dependancies , passing these groovy script i'm calling gralde task (as gradle doesn't seem allow me utilize grape).
the code below way i've been able working. right way?
build.gradle:
configurations { shell } // specify dependancies dependencies { // groovy script task dependancies shell 'org.codehaus.groovy.modules.http-builder:http-builder:0.6' shell 'org.codehaus.groovy:groovy-all:2.3.0' // actual application dependancies compile ... } task cleanupartifactory (dependson: configurations.shell) << { //now add together dependencies root classloader: urlclassloader loader = groovyobject.class.classloader configurations.shell.each {file file -> loader.addurl(file.tourl()) } new groovyshell().run(file('scripts/artifactory.groovy')) }
just treat groovy scripts classes , run them javaexec.
here's example
task yourtask(type: javaexec, dependson: classes) { description = "does stuff" if (project.hasproperty('args')) { // fancy regex args '-pargs="-a -b -c"' , passing them main class def myargs = (project.args =~ /([^\s"']+)|["']([^'"]*)["']/).collect{it[1] ?: it[2]} args myargs } main = 'your.groovyclass' classpath configurations.compile, configurations.runtime, sourcesets.main.output }
the "args" bit can phone call task with
gradle yourtask -pargs="-a -b somevalue"
passing values straight through class.
on subject of grape, have working configuration both allows me call/compile groovy class gradle, , allow grab notation work able phone call script directly.
in groovy class add together appropriate grab , import, e.g.:
@grab(group='org.codehaus.groovy.modules.http-builder', module='http-builder', version='0.6') import groovyx.net.http.*
in build.gradle project, add together following:
configurations { ivy } dependencies { ivy 'org.apache.ivy:ivy:2.3.0' } tasks.withtype(groovycompile) { groovyclasspath += configurations.ivy }
now can phone call groovy script straight with
groovy /path/to/the/groovyclass -a -b somevalue
or utilize gradle task defined earlier.
if don't add together bit of ivy code, class grab in fails compile through gradle.
groovy gradle
No comments:
Post a Comment