我按照 Groovy 2 Cookbook 这本书,在页面60上声明要在Maven Central Repository中设置外部依赖项,我可以依赖@Grab
注释。这是代码:
@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
编译器在前三行发出错误:
unable to resolve a class org.apache.http.impl.client.DefaultHttpClient.
有没有办法解决这个问题?