Groovy Grape is not downloading new revisions

你离开我真会死。 提交于 2019-12-12 15:47:12

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/27136532/groovy-grape-is-not-downloading-new-revisions

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!