2

I want to write a simple Groovy script which uses Apache HttpClient 4.1 and since I don't have its jar, I want to grab it with Grapes. All I have so far in my script is..

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

But when I run this I get an exception..

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

Why is Grapes getting commons logging when I only asked for http client? If it is because the latter needs the former, then do I need to explicitly grab all of the dependent jars of http client myself? How would I even know what they are? Is there a way to tell Grapes to do this on its own?

M. Justin
  • 14,487
  • 7
  • 91
  • 130
AbuMariam
  • 3,282
  • 13
  • 49
  • 82

1 Answers1

6

This is happening because commons-logging is a transitive dependency i.e. a dependency of org.apache.httpcomponents:httpclient.

You are presumably having a problem because your local maven repo doesn't have commons-logging and doesn't know how (or isn't configured) to look for it.

Michael Rutherfurd
  • 13,815
  • 5
  • 29
  • 40
  • Thanks Mike, so how can I tell Grapes to look beyond my local maven repo for jars it doesn't find there? – AbuMariam Jan 21 '16 at 02:19
  • @AbuMariam: Use GrapeResolver: http://docs.groovy-lang.org/latest/html/documentation/grape.html – Jayan Jan 21 '16 at 04:44
  • The transitive dependencies can be seen in the [dependency's pom](https://repo1.maven.org/maven2/org/apache/httpcomponents/httpclient/4.0/httpclient-4.0.pom), or online on the dependency's page at https://mvnrepository.com/artifact/org.apache.httpcomponents/httpclient/4.0. – M. Justin Apr 13 '22 at 04:42