Search code examples
intellij-ideagrailsgroovygroovy-consolegroovy-grape

@Grab not working in intellij IDE for groovy


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.


Solution

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