开发者

Disable automatic download for Groovy grapes

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


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


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>


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜