Groovy Grape不下载新版本 [英] Groovy Grape is not downloading new revisions

查看:105
本文介绍了Groovy Grape不下载新版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



我通过应用程序的API通过Java代码进行抓取,所以可能会有一些pre如果脚本具有@Grab,处理就不那么容易了,如果这很重要的话....

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

地图< String,Object> dependencies = new HashMap< String,Object>();
dependencies.put(group,groupID);
dependencies.put(module,artifactID);
dependencies.put(版本,版本);
dependencies.put(force,true);
dependencies.put(changing,true);

Grape.grab(参数,依赖关系);

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



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

我尝试使用no grapeConfig.xml(即所有默认值,并使用Grape.addResolver添加存储库),并有一个grapeConfig.xml有我的存储库,而且我从另一篇文章中收集的这一行应该告诉它假设缓存有效的时间(除非我错误地解释了这一点,但没有用到

 < property name =ivy.cache.ttl.defaultvalue =2m/> 

我也观察到如果我为该版本指定了*,葡萄会询问库对于元数据,但似乎还不知道有一个更新的版本。而且,一旦我这样做了,它就再也找不到具体的版本了。我必须删除缓存才能恢复到特定版本的功能。



不幸的是,我是张贴在这里的新手,所以不允许包含我在讨论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)。

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

它在某种程度上并不打算,因此会得到奇怪的结果。相反,也许你应该更简单地获取依赖关系,并将Grape / Grab从其中移出。



以下是一些示例代码,您可能会这样做......

p>

  def downloadArtifact(repo,groupId,artifactId,version,e){
println正在获取$ {artifactId} ...
def artifactResUrl =$ {nexusServerUri} $ {resolvePath}?r = $ repo& g = $ groupId& a = $ artifactId& v = $ version& e = $ e
def artifactRes =新的XmlSlurper()。parse(artifactResUrl)
def repoPath = artifactRes.data.repositoryPath
def address =$ {nexusServerUri} $ {contentPath} / $ {repo} $ {repoPath}
文件名=$ {artifactId} - $ version。$ {e}
def file = new File('lib',filename)
def fos = new FileOutputStream(file)
def out = new BufferedOutputStream(fos)
out<<新的URL(地址).openStream()
out.close()
println完成。
}

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)

很明显,这需要进行严格的调整,但应该获得最新的依赖性(它对我的项目需要这样做),如果它与当前版本相同,则不应该显示为不同。


I believe I have everything configured correctly such that grape ought to be asking the repository if there is a new revision, but it isn't. As long as the jar exists in .groovy/grapes it uses it.

I'm doing the grab via Java code via our application's API, so there can be some pre-processing not as easily handled if the script has @Grab, if that matters....

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

Where groupID, artifactID, and version are passed in from the caller's script.

If I delete the grapes cache it always correctly finds the latest revision. If I then upload a new revision of the same jar it doesn't even try to see if there is a new one (I've looked at the Artifactory log, which happens to be the repository I'm using, and it's also confirmed by the fact that the download count it lists is 0).

I've tried using no grapeConfig.xml (i.e. all defaults, and use Grape.addResolver to add repositories), and having a grapeConfig.xml that has my repositories, and also this line, which I gathered from another post is supposed to tell it how long to assume the cache is valid (unless I am misinterpreting that, but didn't work in any case).

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

I've also observed that if I specify "*" for the version, grape DOES ask the repository for the metadata, but still doesn't seem to know that there is a newer revision. Furthermore, once I've done that, it can no longer find the specific version at all. I have to delete the cache to get it back to functioning with specific version.

Unfortunately I'm a newbie to posting here, so am not allowed to include an image of the dependencies I'm talking about as seen in Artifactory, but it would be something like this:

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") correctly returns the -1 version. If I then upload a new revision:

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") doesn't even ask the repository if there is something new, and returns the cached -1 jar.

grab("test","sample","*") asks the repository for metadata, but still returns the cached jar, and then renders grab("test","sample","1.0-SNAPSHOT") inoperative (returns NOT FOUND).

I feel like I must be missing something obvious here...

解决方案

My knee jerk reaction is you are using it in a way that it was not intended and are therefore getting weird results. Instead, perhaps you should simply fetch the dependency more explicitly and leave Grape/Grab out of it.

Here is some sample code how you might do this...

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)

Obviously this needs serious tweaking but should get latest dependency (it did for my project that needed this) and if it same as current, it should not appear as different.

这篇关于Groovy Grape不下载新版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆