SwiX
SwiX

Reputation: 121

Gradle - How to fetch ivy XML files

I have a gradle script that basically fetches jar from our company's repo into current working directory.
What I'd like to do, is add a task that also extracts ivy.xml files in another directory.

build.gradle looks like this :

repositories {  
    ivy {  
        url 'protocol://repo.foocompany.com/'
        credentials {
            username "foo"
            password "bar"
    }
    layout 'pattern', {
        artifact '[organisation]/[module]/[module]-[revision].[ext]'
        ivy '[organisation]/[module]/ivy-[revision].xml'
    }
}

dependencies {
    compile 'com.foocompany:bartifact:rev@ext'
}

task list << {
    configurations.compile.each {
        File file -> println file.name
    }
}

// that's the part I actually use
task fetch(type: Copy) {
    from configurations.compile
    into System.getProperty("user.dir")
}

task fetchXml {
    // and that's where I'm stuck no clue what I should put in there
}

When running the script, my fetch task works just as intended :

$> gradle fetch  
Download protocol://repo.foocompany.com/com.foo/bartifact/ivy-rev.xml  
Download protocol://repo.foocompany.com/com.foo/bartifact/bartifact-rev.ext  
:fetch  

$> ls  
bartifact-rev.ext  

And I can't get that XML file. I've been trying quite a lot of stuff, but I just can't get it anywhere else than manually, from gradle's cache.

Upvotes: 2

Views: 1405

Answers (1)

Johan Stuyts
Johan Stuyts

Reputation: 3697

Simply add a new Ivy repository just for the Ivy files:

repositories {
    ivy {
        // Change the values here to match your environment.
        url 'http://archiecobbs.github.io/ivyroundup/repo/modules/'
        layout 'pattern', {
            artifact '[organisation]/[module]/[revision]/ivy.[ext]'
        }
    }
}

configurations {
    ivyFiles
}

dependencies {
    ivyFiles 'org.apache.geronimo.specs:activation:1.1@xml'
}

task downloadIvyFiles(type: Copy) {
    from configurations.ivyFiles
    into temporaryDir
}

Upvotes: 2

Related Questions