@Grab not working in intellij IDE for groovy

2.9k Views Asked by At

I am pretty new to groovy , ans was practicing to make a REST call using the http-builder package , I am trying to add the dependency using a @Grab annotation , but it doesn't download the dependencies , the annotation is not working ,

My Code :

import groovyx.net.http.ContentType
import groovyx.net.http.RESTClient

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

def restClient = RESTClient('http://api.icmdb.com')
restClient.contentType = ContentType.JSON
restClient.get(path:'/jokes/random'){response,json->
    println response.status
    println json
}

The exception I am getting :

 Caught: groovy.lang.MissingMethodException: No signature of method: com.groovy.practice.RESTCall.RESTClient() is applicable for argument types: (String) values: [http://api.icmdb.com]
groovy.lang.MissingMethodException: No signature of method: com.groovy.practice.RESTCall.RESTClient() is applicable for argument types: (String) values: [http://api.icmdb.com]

So basically its not downloading the http-builder and hence its not finding the signature for the type RESTClient.

My groovy version is : 2.6.0-alpha-1 Intellij Version : 2017.2.3

is there anything to initiate Grape in groovy or intellij IDE , can anyone please help , I am stuck here.

2

There are 2 best solutions below

2
On BEST ANSWER

Try placing caret on Grapes dependency & press Alt + Enter then grab dependencies.

0
On

My first idea would be to discard problems with the IDE. Please try to execute your Groovy program outside the IDE, with the groovy interpreter. Should the problem arise again, I would check my ~/.groovy/grapeConfig.xml.

Is there any connection issue or corporative proxy that would prevent you to get straight to maven central internet site? In that case, should you try to configure proxy options in your Groovy call? Or, if you are in a corporative environment, is there any kind of corporative repository such as Artifactory or Nexus that you could try to use in order to circumvent your problem?