2

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.

M. Justin
  • 14,487
  • 7
  • 91
  • 130
Tushar Kumar
  • 65
  • 2
  • 7

2 Answers2

8

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

Mike W
  • 3,853
  • 2
  • 11
  • 18
  • Thanks Mike , it worked but I have one more follow up question on this , is this not like the most frustrating bug , I am already adding a @Grab annotation at the top but I have to manually grab the dependencies , then whats the point of adding the annotation , Thanks a lot for suggesting this but do you know if this is a bug either in the IDE or in Groovy ? – Tushar Kumar Sep 25 '17 at 15:13
  • I know it's a pain, I believe there's a feature request to add automatic grape downloads to a future release of intellij somewhere – Mike W Sep 25 '17 at 17:26
0

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?

Jorge_B
  • 9,712
  • 2
  • 17
  • 22