Groovy Grapes won't download new versions

I believe everything is set up correctly, so grapes should ask the repository if there is a new revision, but it is not. As long as the jar exists in .groovy / grapes, it uses it.

I am doing the capture with Java code via our Application API, so there might be some preprocessing not so easy to handle if the script is @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 from the calling script.

If I delete the grape cache it always finds the latest version correctly. If I then download a new revision of the same jar, it doesn't even try to see if there is a new one (I looked at the Artifactory log, which I think is the repository I am using, and it also confirmed in fact that the download count list is 0).

I have tried using grapeConfig.xml (i.e. all defaults and using Grape.addResolver to add repositories) and having grapeConfig.xml with my repos and also this line that I gathered from another post should say how long to assume that the cache is valid (if I'm not mistaken, but did not work in any way).

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

      

I also noticed that if I specify "*" for the version, grapes will ask the repository for metadata, but doesn't seem to know that a newer version exists. Also, once I have done this, it can no longer find the specific version. I have to delete the cache to get it back to working with a specific version.

Unfortunately I'm new to posting here, so I'm not allowed to include an image of the dependencies I'm talking about as shown 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 -1 version. If I then download the new version:

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 a cached -1 jar.

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

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

+3


source to share


1 answer


My reaction to the knee jerk is that you use it in a way that is not intended and therefore gets weird results. Instead, maybe you just need to explicitly get the dependency and leave Grape / Grab out of it.

Here is some sample code how you can do it ...



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 requires some serious tweaking, but should get the last dependency (it was for my project that needed it) and if it's the same as the current one, it shouldn't look different.

+1


source







All Articles