Reputation: 626
I need to use some classes in httpclient.jar when building a project in Jenkins. I added this jar to both {Groovy_Classpath}\lib and {Jenkins_Path}\plugins\groovy\WEB-INF\lib and tried to imported into my job (also see the screenshot below):
import jenkins.model.*
import hudson.model.*
import groovy.*
import org.apache.http.*
HttpClient httpClient = HttpClientBuilder.create().build();
It has two issues:
startup failed:
Script1.groovy: 6: unable to resolve class HttpClient
@ line 6, column 12.
HttpClient httpClient = HttpClientBuilder.create().build();
^
1 error
So I removed HttpClient and saw another:
Caught: groovy.lang.MissingPropertyException: No such property: HttpClientBuilder for class: xxxx
groovy.lang.MissingPropertyException: No such property: HttpClientBuilder
I guess probably they meant the same thing - the class couldn't be found. But I have no idea how to resolve as I've added the jar to classpath...
Updated on the basis of Mike W's suggesion
Upvotes: 1
Views: 2819
Reputation: 3932
Try getting the dependency using Grape, add the following to the top of your script.
@Grab(group='org.apache.httpcomponents', module='httpclient', version='4.5.3'))
Upvotes: 1