kaakaa Blog

この世は極楽 空にはとんぼ

GroovyでHTTPBuilderをGrabしようとしたらエラー

@Grab(group='org.codehaus.groovy.modules.http-builder', module='http-builder', version='0.5.1' )
 
def http = new groovyx.net.http.HTTPBuilder('http://www.codehaus.org')

と実行すると

org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
General error during conversion: Error grabbing Grapes -- [download failed: commons-codec#commons-codec;1.3!commons-codec.jar, download failed: xerces#xercesImpl;2.8.1!xercesImpl.jar, download failed: xml-apis#xml-apis;1.3.03!xml-apis.jar]

java.lang.RuntimeException: Error grabbing Grapes -- [download failed: commons-codec#commons-codec;1.3!commons-codec.jar, download failed: xerces#xercesImpl;2.8.1!xercesImpl.jar, download failed: xml-apis#xml-apis;1.3.03!xml-apis.jar]
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
	at org.codehaus.groovy.reflection.CachedConstructor.invoke(CachedConstructor.java:77)
...

となり、エラー。
次はGrapeコマンドでhttp-builderのインストールを試みる。

grape install org.codehaus.groovy.modules.http-builder http-builder 0.5.2

これもエラー

problems summary ::
:: WARNINGS
[NOT FOUND ] commons-codec#commons-codec;1.3!commons-codec.jar (0ms) ==== localm2: tried file:/Users/****/.m2/repository/commons-codec/commons-codec/1.3/commons-codec-1.3.jar [NOT FOUND ] xerces#xercesImpl;2.8.1!xercesImpl.jar (0ms) ==== localm2: tried file:/Users/****/.m2/repository/xerces/xercesImpl/2.8.1/xercesImpl-2.8.1.jar [NOT FOUND ] xml-apis#xml-apis;1.3.03!xml-apis.jar (0ms) ==== localm2: tried file:/Users/****/.m2/repository/xml-apis/xml-apis/1.3.03/xml-apis-1.3.03.jar
USE VERBOSE OR DEBUG MESSAGE LEVEL FOR MORE DETAILS

なんだかMavenのローカルリポジトリにそれぞれのjarが無いとかで怒られてる感じ。

無いと言われたjarを落として、然るべき場所に配置して、もう一回Grapeコマンド。
jarを落とす時に"mvn install hogehoge"みたいな感じで落としたかったけど、やり方わからなかったので、手動で落として配置。

$ Grape install org.codehaus.groovy.modules.http-builder http-builder 0.5.2
loading settings :: url = jar:file:/Users/****/Documents/groovy-1.8.6/lib/ivy-2.2.0.jar!/org/apache/ivy/core/settings/ivysettings.xml
resolving dependencies :: caller#all-caller;working
confs: [default] found org.codehaus.groovy.modules.http-builder#http-builder;0.5.2 in codehaus found org.apache.httpcomponents#httpclient;4.0.3 in ibiblio found org.apache.httpcomponents#httpcore;4.0.1 in ibiblio found commons-logging#commons-logging;1.1.1 in localm2 found commons-codec#commons-codec;1.3 in localm2 found net.sf.json-lib#json-lib;2.3 in ibiblio found commons-beanutils#commons-beanutils;1.8.0 in localm2 found commons-collections#commons-collections;3.2.1 in localm2 found commons-lang#commons-lang;2.4 in localm2 found net.sf.ezmorph#ezmorph;1.0.6 in ibiblio found org.codehaus.groovy#groovy;1.7.11 in codehaus [1.7.11] org.codehaus.groovy#groovy;[1.5,1.7.99] found antlr#antlr;2.7.7 in localm2 found asm#asm;3.2 in ibiblio found asm#asm-commons;3.2 in ibiblio found asm#asm-tree;3.2 in ibiblio found asm#asm-util;3.2 in ibiblio found asm#asm-analysis;3.2 in ibiblio found net.sourceforge.nekohtml#nekohtml;1.9.9 in ibiblio found xerces#xercesImpl;2.8.1 in localm2 found xml-apis#xml-apis;1.3.03 in localm2 found xml-resolver#xml-resolver;1.2 in ibiblio downloading file:/Users/****/.m2/repository/commons-codec/commons-codec/1.3/commons-codec-1.3.jar ... [SUCCESSFUL ] commons-codec#commons-codec;1.3!commons-codec.jar (10ms) downloading file:/Users/****/.m2/repository/xerces/xercesImpl/2.8.1/xercesImpl-2.8.1.jar ... [SUCCESSFUL ] xerces#xercesImpl;2.8.1!xercesImpl.jar (15ms)

上手く行ったようだ。

んで、元のコード動かしたら特にエラーも出ずに動いてくれた。

GroovyやGradleだとMavenから逃れられると思ってたけど、そうも行かないようだ。