How do I copy artifacts from nexus to local filesystem

We need a script/command that fetches a bunch of war files out of our nexus and copies them to different directories on the local filesystem for deploy them afterwards.

For now we are doing this with maven using the copy goal while installing, but this is ugly and it fetches all transitive dependencies, what we don’t need.

As we have a nexus, I thought gradle might have an easy way to fetch an artifact from nexus and copy it.

Is there an easy way to achieve this?

1 Like
repositories {
  configurations {
  dependencies {
    wars "my:war:1.0@war"
  task copy(type: Copy) {
    from configurations.wars
    into "wars"

Thanks, that works great.

I added an transtive false to my configurations.

Now I want to chain some tasks, and I get this error if I try to depend on an copy tasks:

Could not find property 'copy' on task ':[file collection]'.

This is my (additional) code:

task copyAll << {
    println "Copy all"
task copyAll.dependsOn copy

And, another problem, is it possible to rename the for a certain war (e.g. ROOT.war)?

‘transitive = false’ is an alternative to ‘@war’. It’s ‘copyAll.dependsOn copy’, not ‘task copyAll.dependsOn copy’. The ‘task’ keyword is only used for declaring a new task.

Hello Peter,

I have created a task, just the way You mentioned

dependencies {
    projectx group: "com.chavasoft", name:, version: project.version.toString(), ext: 'war'
  ext.downloadDir = file("$buildDir")
  task fetchWar(type: Copy) {
    from configurations.projectx
    into downloadDir
    doLast {
            println "Downloaded war"

but after running it on my CI machine,

I get the following message all the time

:fetchWar (Thread[main,5,main]) started. :fetchWar Skipping task ‘:fetchWar’ as it has no source files. :fetchWar UP-TO-DATE :fetchWar (Thread[main,5,main]) completed. Took 0.017 secs.

do You know what could be the problem?

Thanks in advance