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?