【问题标题】:Groovy's Ivy cache (@Grab) not caching?Groovy 的 Ivy 缓存(@Grab)没有缓存?
【发布时间】:2012-11-07 06:35:59
【问题描述】:

我正在使用 groovyConsole(版本 1.8.1)运行这个简单的 groovy 脚本:

println "Start " + new Date()
@Grab( 'log4j:log4j:1.2.16' )
import org.apache.log4j.Logger
println "End " + new Date()

通常,它执行得非常快(~ 0 秒)。

但是,有时(每约 5 次运行一次),它会在完成运行前暂停 3-5 秒。 我正在使用 Wireshark (here is the capture) 进行嗅探,并看到对 repository.codehaus.org 的 HTTP 请求(我在 Wireshark 流中看到一些 404 响应,但脚本设法运行,所以显然在某个时候找到了 jar)

我的问题是 - 一旦脚本运行一次,它通过 @Grab 下载的 jar 是否会永久缓存?为什么经常查询实际的 Ivy/Maven 存储库?

【问题讨论】:

  • 这就是脚本中的@Grab 吗?我只问,因为 Ivy(支持 @Grab)似乎正在寻找大量不相关的软件包。我不是常春藤专家:-/
  • @tim_yates - 是的,这就是整个脚本。

标签: groovy grape


【解决方案1】:

文件应缓存在~/.groovy/grapes 中。如果您使用 -Divy.message.logger.level=4 重新运行脚本,您将从 ivy 获得一些可能有用的调试信息。

此外,如果您的葡萄需要很长时间才能解决,您可以告诉 ivy 减少检查的频率。将默认的 ivy 配置从 here 复制到 ~/.groovy/grapeConfig.xml 并将属性 ivy.cache.ttl.default 添加到一段时间以等待再次检查。例如:

<ivysettings>
  <property name="ivy.cache.ttl.default" value="24h"/>
  <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="codehaus" root="http://repository.codehaus.org/" m2compatible="true"/>
      <ibiblio name="ibiblio" m2compatible="true"/>
      <ibiblio name="java.net2" root="http://download.java.net/maven/2/" m2compatible="true"/>
    </chain>
  </resolvers>
</ivysettings>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-04-29
    • 1970-01-01
    • 1970-01-01
    • 2011-11-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-22
    相关资源
    最近更新 更多