【问题标题】:Groovy Grape is not downloading new revisionsGroovy Grape 没有下载新的修订版
【发布时间】:2015-01-24 00:52:01
【问题描述】:

我相信我已经正确配置了所有内容,因此葡萄应该询问存储库是否有新修订,但事实并非如此。只要 jar 存在于 .groovy/grapes 中,它就会使用它。

我正在通过我们应用程序的 API 通过 Java 代码进行抓取,因此如果脚本有 @Grab,可能会有一些预处理不太容易处理,如果这很重要的话......

Map<String,Object> args = new HashMap<String, Object>();
args.put("validate", true);
args.put("classLoader", gcl);

Map<String,Object> dependencies = new HashMap<String, Object>();
dependencies.put("group", groupID);
dependencies.put("module", artifactID);
dependencies.put("version", version);
dependencies.put("force", true);
dependencies.put("changing", true);

Grape.grab(args, dependencies);

其中 groupID、artifactID 和 version 是从调用者的脚本传入的。

如果我删除葡萄缓存,它总是能正确找到最新版本。如果我然后上传同一个 jar 的新版本,它甚至不会尝试查看是否有新版本(我查看了 Artifactory 日志,恰好是我正在使用的存储库,并且它也得到了确认事实上,它列出的下载计数是 0)。

我尝试不使用grapeConfig.xml(即所有默认值,并使用Grape.addResolver 添加存储库),并拥有一个包含我的存储库的grapeConfig.xml,以及我从另一篇文章中收集的这一行是应该告诉它假设缓存有效多长时间(除非我误解了这一点,但在任何情况下都不起作用)。

<property name="ivy.cache.ttl.default" value="2m"/>

我还观察到,如果我为版本指定“*”,grape 确实会向存储库询问元数据,但似乎仍然不知道有更新的版本。此外,一旦我这样做了,它就再也找不到特定的版本了。我必须删除缓存才能使其恢复使用特定版本。

不幸的是,我是在这里发帖的新手,所以不允许包含我在 Artifactory 中看到的我正在谈论的依赖项的图像,但它会是这样的:

test
|----sample
|--------1.0-SNAPSHOT
|----------sample-1.0-20141125.185508-1.jar
|----------sample-1.0-20141125.185508-1.pom

grab("test","sample","1.0-SNAPSHOT") 正确返回 -1 版本。如果我再上传一个新版本:

test
|----sample
|--------1.0-SNAPSHOT
|----------sample-1.0-20141125.185508-1.jar
|----------sample-1.0-20141125.185508-1.pom
|----------sample-1.0-20141125.191916-2.jar
|----------sample-1.0-20141125.191916-2.pom

grab("test","sample","1.0-SNAPSHOT") 甚至不会询问存储库是否有新内容,而是返回缓存的 -1 jar。

grab("test","sample","*") 向存储库请求元数据,但仍然返回缓存的 jar,然后呈现 grab("test","sample","1.0-SNAPSHOT") 无效(返回 NOT FOUND)。

我觉得我必须在这里遗漏一些明显的东西......

【问题讨论】:

    标签: java groovy grape


    【解决方案1】:

    我的下意识反应是,您以非预期的方式使用它,因此得到了奇怪的结果。相反,也许您应该更明确地获取依赖项并将 Grape/Grab 排除在外。

    这里有一些示例代码,你可以如何做到这一点......

    def downloadArtifact(repo, groupId, artifactId, version, e) {
        println "Fetching ${artifactId}..."
        def artifactResUrl = "${nexusServerUri}${resolvePath}?r=$repo&g=$groupId&a=$artifactId&v=$version&e=$e"
        def artifactRes = new XmlSlurper().parse(artifactResUrl)
        def repoPath = artifactRes.data.repositoryPath
        def address = "${nexusServerUri}${contentPath}/${repo}${repoPath}"
        def filename = "${artifactId}-$version.${e}"
        def file = new File('lib', filename)
        def fos = new FileOutputStream(file)
        def out = new BufferedOutputStream(fos)
        out << new URL(address).openStream()
        out.close()
        println "Done."
    }
    
    nexusServerUri = 'http://some.server.com:8081/nexus'
    resolvePath = '/service/local/artifact/maven/resolve'
    contentPath = '/content/groups'
    repo = 'sprn-maven2'
    groupId = 'com.abc.somethign'
    version = '1.0-SNAPSHOT'
    e = 'jar'
    
    downloadArtifact(repo, groupId, 'artifact-id', version, e)
    

    显然这需要认真调整,但应该获得最新的依赖项(它为我需要这个的项目做了)​​,如果它与当前相同,它不应该看起来不同。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-02-23
      • 1970-01-01
      • 2013-10-09
      • 2019-05-28
      • 1970-01-01
      • 1970-01-01
      • 2021-02-26
      • 1970-01-01
      相关资源
      最近更新 更多