0

I am trying to use the below lines to get API response, but its not working for me. Please help me.

Groovy ver = 2.4.15 OS = windows 7

@Grab(group='org.codehaus.groovy.modules.http-builder',module='http-builder',version='0.7.1')

import groovyx.net.http.HTTPBuilder

enter image description here

ernest_k
  • 44,416
  • 5
  • 53
  • 99
user9473385
  • 131
  • 2
  • 8
  • How is it "not working"? Please describle the failure. – ernest_k Jun 02 '18 at 19:24
  • Hello Ernest, I have added the image may be that will help you understand better. – user9473385 Jun 02 '18 at 20:07
  • I can see that dependency in maven central. Do you have internet connection for Groovy to fetch it if it isn't in your local m2 repo? – ernest_k Jun 02 '18 at 20:10
  • i tried your @grab annotation - works fine. so check the internet connection. maybe you are behind the proxy? could you provide the full stack trace? also you could activate debug output of the grab: https://stackoverflow.com/questions/3722280/groovy-grape-verbose – daggett Jun 02 '18 at 21:59

1 Answers1

0

As mentioned in the comments, I think the best place to start would be to run your script with the following flag turned on:

~> groovy -Dgroovy.grape.report.downloads=true <yourscript>

that should give you some logging indicating what the grape resolution is doing and hopefully where it tried to download the file from when it failed.

For an overview of the grape resolution mechanics, you can refer to the groovy documentation on grapes.

My guess is that groovy is trying multiple resolvers (i.e. maven central, jcenter, etc) and one of them is failing early even though a later one has the artifact. In a situation like this the resolution engine naturally should keep trying until it finds a working artifact but I have seen things fail this way before.

To modify the resolution order and behavior, you should look at the file:

<your user home dir>/.groovy/grapeConfig.xml

where, if the file does not exist, groovy uses the following default data for the file:

<ivysettings>
  <settings defaultResolver="downloadGrapes"/>
  <resolvers>
    <chain name="downloadGrapes" returnFirst="true">
      <filesystem name="cachedGrapes">
        <ivy pattern="${user.home}/.groovy/grapes/[organisation]/[module]/ivy-[revision].xml"/>
        <artifact pattern="${user.home}/.groovy/grapes/[organisation]/[module]/[type]s/[artifact]-[revision](-[classifier]).[ext]"/>
      </filesystem>
      <ibiblio name="localm2" root="file:${user.home}/.m2/repository/" checkmodified="true" changingPattern=".*" changingMatcher="regexp" m2compatible="true"/>
      <!-- todo add 'endorsed groovy extensions' resolver here -->
      <ibiblio name="jcenter" root="https://jcenter.bintray.com/" m2compatible="true"/>
      <ibiblio name="ibiblio" m2compatible="true"/>
    </chain>
  </resolvers>
</ivysettings>

(from the groovy github repo)

Two things to note here:

  • The returnFirst attribute. The resolution engine will try the resolvers one by one and return the first hit for this specific artifact. If my hunch is correct, this is not working correctly and an early resolver is failing and not giving a later resolver a chance to resolve the artifact.
  • The list of resolvers is ordered so changing this order will affect the result.

So, long story short: turn on debugging and see if that gives anything.

Then either modify or create the grapeConfig.xml file and either:

  • change the order of the ibiblio elements to change the resolution order
  • add another maven resolver (i.e. add another ibiblio node) for a target you have verified has the artifact (and add it first in the chain to make sure one of the others does not fail first).
  • or play with the returnFirst flag to see if setting it to false resolves your issue
Matias Bjarland
  • 4,124
  • 1
  • 13
  • 21