Groovy Grape没有下载新版本

时间:2014-11-25 20:57:03

标签: java groovy grape

我相信我已经正确配置了所有内容,以至于葡萄应该询问存储库是否有新版本,但它不是。只要罐子存在于.groovy / grape中,它就会使用它。

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

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和版本。

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

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

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

我还注意到,如果我指定&#34; *&#34;对于该版本,葡萄DOES向存储库询问元数据,但似乎仍然不知道有更新的版本。此外,一旦我完成了,它就再也找不到特定的版本。我必须删除缓存以使其恢复到特定版本的功能。

不幸的是我在这里发布了一个新手,所以我不允许在Artifactory中包含我所谈论的依赖关系的图像,但它会是这样的:

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

抓取(&#34;测试&#34;,&#34;示例&#34;,&#34; 1.0-SNAPSHOT&#34;)正确返回-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

抓住(&#34;测试&#34;,&#34;示例&#34;,&#34; 1.0-SNAPSHOT&#34;)甚至不询问存储库是否有新的东西,并且返回缓存的-1 jar。

抓取(&#34;测试&#34;,&#34;示例&#34;,&#34; *&#34;)询问存储库的元数据,但仍然返回缓存的jar,然后渲染抓取(&#34;测试&#34;,&#34;样品&#34;,&#34; 1.0-SNAPSHOT&#34;)不起作用(返回NOT FOUND)。

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

1 个答案:

答案 0 :(得分: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)

显然这需要进行严格的调整,但应该获得最新的依赖(它对我的项目需要这样做),如果它与当前相同,它应该看起来不同。

相关问题