how to import http-builder

2,122 views
Skip to first unread message

Emmet Murphy

unread,
Jan 24, 2014, 7:02:34 PM1/24/14
to job-dsl...@googlegroups.com
Am new to groovy and the Job DSL and unclear on how to import a package like http-builder. With the following code, line 6 fails with "unable to resolve class HTTPBuilder."

import groovy.grape.Grape
groovy.grape.Grape.grab([group:'org.codehaus.groovy.modules.http-builder', 
    module:'http-builder', version:'0.6.0'])
import groovyx.net.http.*

def myApi = new HTTPBuilder( 'https://my.sample.com' )

What am I missing?

The underlying need for http-builder is to authenticate with the API, otherwise would use "new URL('https://my.sample.com')."


Emmet

Justin Ryan

unread,
Jan 24, 2014, 7:11:19 PM1/24/14
to job-dsl-plugin
I believe you have to use the annotation version of @Grab, to properly effect the classpath. Try

@Grab(group:'org.codehaus.groovy.modules.http-builder', module:'http-builder', version:'0.6.0')

import groovyx.net.http.*


--
You received this message because you are subscribed to the Google Groups "job-dsl-plugin" group.
To unsubscribe from this group and stop receiving emails from it, send an email to job-dsl-plugi...@googlegroups.com.
To post to this group, send email to job-dsl...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/job-dsl-plugin/ded903dc-e3b2-4560-87fd-502015a17a13%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Emmet Murphy

unread,
Jan 24, 2014, 7:30:07 PM1/24/14
to job-dsl...@googlegroups.com
The @Grab annotation fails with "error in opening zip file". Following is the stack trace, in case it is helpful...

Caused by: BUG! exception in phase 'conversion' in source unit '/my/sample_job_dsl.groovy' error in opening zip file
at org.codehaus.groovy.control.CompilationUnit.applyToSourceUnits(CompilationUnit.java:847)
at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:548)
at org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:524)
at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:501)
at groovy.lang.GroovyClassLoader.doParseClass(GroovyClassLoader.java:306)
at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:287)
at groovy.util.GroovyScriptEngine$ScriptClassLoader.parseClass(GroovyScriptEngine.java:197)
at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:267)
at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:214)
at groovy.util.GroovyScriptEngine.loadScriptByName(GroovyScriptEngine.java:470)
at groovy.util.GroovyScriptEngine.createScript(GroovyScriptEngine.java:539)
at javaposse.jobdsl.dsl.DslScriptLoader.runDslEngineForParent(DslScriptLoader.java:60)
at javaposse.jobdsl.dsl.DslScriptLoader.runDslEngine(DslScriptLoader.java:93)
at javaposse.jobdsl.Run.main(Run.java:43)
... 6 more
Caused by: java.util.zip.ZipException: error in opening zip file
at java.util.zip.ZipFile.open(Native Method)
at java.util.zip.ZipFile.<init>(ZipFile.java:128)
at java.util.jar.JarFile.<init>(JarFile.java:136)
at java.util.jar.JarFile.<init>(JarFile.java:73)
at sun.net.www.protocol.jar.URLJarFile.<init>(URLJarFile.java:72)
at sun.net.www.protocol.jar.URLJarFile.getJarFile(URLJarFile.java:48)
at sun.net.www.protocol.jar.JarFileFactory.get(JarFileFactory.java:55)
at sun.net.www.protocol.jar.JarURLConnection.connect(JarURLConnection.java:104)
at sun.net.www.protocol.jar.JarURLConnection.getInputStream(JarURLConnection.java:132)
at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.setupCurrentEntity(XMLEntityManager.java:650)
at com.sun.org.apache.xerces.internal.impl.XMLVersionDetector.determineDocVersion(XMLVersionDetector.java:186)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:779)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:744)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:128)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1208)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:543)
at javax.xml.parsers.SAXParser.parse(SAXParser.java:395)
at javax.xml.parsers.SAXParser.parse(SAXParser.java:277)
at org.apache.ivy.core.settings.XmlSettingsParser.doParse(XmlSettingsParser.java:160)
at org.apache.ivy.core.settings.XmlSettingsParser.parse(XmlSettingsParser.java:150)
at org.apache.ivy.core.settings.IvySettings.load(IvySettings.java:412)
at org.apache.ivy.core.settings.IvySettings$load.call(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:42)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
at groovy.grape.GrapeIvy.<init>(GrapeIvy.groovy:87)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at java.lang.Class.newInstance0(Class.java:357)
at java.lang.Class.newInstance(Class.java:310)
at groovy.grape.Grape.getInstance(Grape.java:101)
at groovy.grape.Grape.grab(Grape.java:136)
at groovy.grape.GrabAnnotationTransformation.visit(GrabAnnotationTransformation.java:283)
at org.codehaus.groovy.transform.ASTTransformationVisitor$3.call(ASTTransformationVisitor.java:302)
at org.codehaus.groovy.control.CompilationUnit.applyToSourceUnits(CompilationUnit.java:843)
... 19 more

Emmet Murphy

unread,
Jan 24, 2014, 8:20:37 PM1/24/14
to job-dsl...@googlegroups.com
Solved this--had forgotten to point jenkins to maven. Working through other issues with maven, but probably have a handle on it.

Thanks for your help. 

John Shields

unread,
Mar 31, 2014, 5:41:55 PM3/31/14
to job-dsl...@googlegroups.com
Emmet,

Can you clarify "had forgotten to point jenkins to maven"?

I'm seeing this exact stacktrace when trying to use @Grab running the DSL locally in standalone mode on my workstation.

Thanks!

John

Emmet Murphy

unread,
Mar 31, 2014, 6:12:49 PM3/31/14
to job-dsl...@googlegroups.com
John, 

In Manage Jenkins -> Configure System, there is a section labelled "Maven Installations". You may need to click "Add Maven" and either check "Install Automatically" or uncheck and enter MAVEN_HOME to point Jenkins to an already-installed version (as was needed in our case). I think this step is listed in the documentation somewhere.

Emmet

Maurício Borges Silva

unread,
May 29, 2014, 10:30:18 PM5/29/14
to job-dsl...@googlegroups.com
Hi John,

I know it's a bit old thread, but have you solved the @Grab issue when running the job-dsl locally in standalone mode?

Thanks!

Mauricio
Reply all
Reply to author
Forward
0 new messages