tags:

views:

35

answers:

1

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).

A: 

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
Thanks, this might work as a temporary solution, however isn't portable enough - at some places installing is just not an option.
icyrock.com