2

I follow the book Groovy 2 Cookbook, on the page 60 it states that to set an external dependency available in Maven Central Repository I can rely on @Grab annotation. Here's the code:

@Grab('org.apache.httpcomponents:httpclient:4.2.1')
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.client.methods.HttpGet 

def httpClient = new DefaultHttpClient() 
def url = 'http://www.google.com/search?q=Groovy'
def httpGet = new HttpGet(url) 

def httpResponse = httpClient.execute(httpGet) 
new File('result.html').text = httpResponse.entity.content.text

The compiler issues an error on the first three lines:

unable to resolve a class org.apache.http.impl.client.DefaultHttpClient.

Is there a way to resolve this issue?

Atul Dwivedi
  • 1,452
  • 16
  • 29
Eugenia Ozirna
  • 505
  • 2
  • 14
  • Your example works for me with Groovy 2.4.5. Is is possible that your computer is behind a proxy server? - http://docs.groovy-lang.org/latest/html/documentation/grape.html#Grape-Proxysettings – Michael Easter Sep 16 '16 at 17:15
  • Possible duplicate of [Error grabbing Grapes ... unresolved dependency ... not found](http://stackoverflow.com/questions/24873542/error-grabbing-grapes-unresolved-dependency-not-found) – pczeus Sep 18 '16 at 01:31
  • Works for me too. How did you invoke the compiler? – MarkHu Jan 31 '17 at 21:55

0 Answers0