Copying depedencies to separate folders

I am trying to copy dependencies to separate folders but am struggling to come up with a clean solution. This is what I have come up with so far:

configurations {
  depsA
  depsB
}

dependencies {
   depsA 'A'
   depsB 'B'
}

task copyDependenciesA(type: Copy) {
   from configurations.depsA
   into 'depsA'
}

task copyDependenciesB(type: Copy) {
   from configurations.depsB
   into 'depsB'
}

Can this be done in a cleaner way so I don’t need two tasks and two configurations?

Copy tasks cannot have more than one target “root” directory, so you cannot do what you want using a single copy task.

Some ideas:

  1. Make your own task that uses the Project.copy method (will have to handle task inputs and outputs yourself if that’s important to you).

  2. You could condense the code if you have a lot of repetition and there’s a mapping/pattern to follow. You could also combine them under one umbrella task.

    ext {
    configsWithCopy = [‘A’, ‘B’]
    }
    task copyAll {
    dependsOn configsWithCopy.collect {
    def depConfig = configurations.maybeCreate( “deps${it}” )
    tasks.create( “copyDependencies${it}”, Copy ) {
    from depConfig
    into “deps${it}”
    }
    }
    }
    dependencies {
    depsA 'A’
    depsB ‘B’
    }

Thanks for your input. I ended up using a variant of your second solution.