3

A sample script ss.groovy:

@Grab(group='org.codehaus.groovy.modules.http-builder', 
      module='http-builder', 
      version='0.5.0')
import groovyx.net.http.HTTPBuilder

println('done')

for some reason takes ~25 seconds to load when run with

groovy ss.groovy

and ~5 seconds when run with

groovy -Dgroovy.grape.autoDownload=false ss.groovy

as per this StackOverflow explanation. I tried doing manual initialization with

Grape.enableAutoDownload = false
Grape.grab(group:'org.codehaus.groovy.modules.http-builder', 
           module:'http-builder',
           version:'0.5.0')
import groovyx.net.http.HTTPBuilder
println('done')

but this fails on import with:

/tmp/ss.groovy: 3: unable to resolve class groovyx.net.http.HTTPBuilder
 @ line 3, column 1.
  import groovyx.net.http.HTTPBuilder
  ^

Is there a contained way to either:

  • Make it not download the artifacts automatically (preferred, as it allows for solving other issues, e.g. external site down while an artifact already exists in the local cache)
  • Make it startup faster in any other way

By contained I mean that all additional instructions should be either within script or, if no such one exists, an acceptable default (e.g. don't check the cached artifacts for updates - I would still, however, like to have automatic downloads globally) to be put in some of groovy config files (e.g. ~/.groovy/grapeConfig.xml or similar).

M. Justin
  • 14,487
  • 7
  • 91
  • 130
icyrock.com
  • 27,952
  • 4
  • 66
  • 85

3 Answers3

3

Update: The issue has been fixed, @GrabConfig(autoDownload=false) will be available in Groovy 2.2

Andre Steingress
  • 4,381
  • 28
  • 28
0

Why not install a repository manager locally?

http://nexus.sonatype.org/

I use Nexus to proxy and cache all my 3rd party repositories. Groovy is the configured to retrieve from either it's local cache or Nexus:

<ivysettings>
  <settings defaultResolver="downloadGrapes"/>
  <resolvers>
    <chain name="downloadGrapes">
      <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].[ext]"/>
      </filesystem>
      <!-- Local Nexus Repository -->
      <ibiblio name="nexus" root="http://localhost:8081/nexus/repositories/public" m2compatible="true"/>
    </chain>
  </resolvers>
</ivysettings>
Mark O'Connor
  • 76,015
  • 10
  • 139
  • 185
  • Thanks, this might work as a temporary solution, however isn't portable enough - at some places installing is just not an option. – icyrock.com Sep 08 '10 at 00:01
0

This doesn't seem to be possible with the current (Groovy 1.8.1) implementation. I created an improvement ticket: http://jira.codehaus.org/browse/GROOVY-4943.

icyrock.com
  • 27,952
  • 4
  • 66
  • 85