1

我想寫一個簡單的使用Apache HttpClient 4.1的Groovy腳本,由於我沒有它的jar,我想用Grapes抓住它。所有我至今在我的腳本..爲什麼葡萄抓住我沒有要求的罐子?

@Grab(group='org.apache.httpcomponents', module='httpclient', version='4.0') 
import org.apache.http.impl.client.DefaultHttpClient; 

但是當我運行此我得到一個異常..

java.lang.RuntimeException: Error grabbing Grapes -- [download failed: commons-logging#commons-logging;1.1.1!commons-logging.jar] 

爲什麼葡萄越來越通用日誌的時候,我只問http客戶端?如果是因爲後者需要前者,那麼我是否需要自己明確抓取所有依賴的http客戶端jar?我怎麼會知道他們是什麼?有沒有辦法告訴葡萄自己做這件事?

回答

5

發生這種情況的原因是commons-logging是一個傳遞依賴項,即org.apache.httpcomponents的依賴項:httpclient。

你大概有問題,因爲你的本地maven回購沒有commons-logging,也不知道如何(或沒有配置)來查找它。

+0

感謝邁克,那麼我該如何告訴葡萄超越我的本地maven回購庫,以找到它在那裏找不到的罐子? – AbuMariam

+0

@AbuMariam:使用GrapeResolver:http://docs.groovy-lang.org/latest/html/documentation/grape.html – Jayan