How to export dependencies to different locations with Gradle?
<p>I wanted to avoid creating different configurations because I would like to have many different behaviors associated with my dependencies, not just this one.</p>

<p>So thanks to 'ext' properties I am able to associate my own data to the dependencies:</p>

<pre><code>runtime 'org.apache.logging.log4j:log4j-api:2.5'
runtime 'org.apache.lucene:lucene-core:5.4.1'
runtime('hsqldb:hsqldb:1.8.0.10') { ext.exportTo = 'jdbc' }
</code></pre>

<p>Now I want to exploit it to copy the dependencies into 'libs/' by default, and 'libs/${exportTo}/' if exportTo is specified.</p>

<pre><code>task copyRuntimeLibs(type: Copy) {
  into "build/dependencies"
  from configurations.runtime
}
</code></pre>

<p>So I'm trying to create a dynamically created configuration for those special dependencies, and a dynamically created task to do the job, which I link to the main task 'copyRuntimeLibs':</p>

<pre><code>configurations.runtime.allDependencies.withType(ExternalModuleDependency).each { d -&gt;
  if (d.hasProperty("exportTo")) {
    def key = "${d.group}:${d.name}:${d.version}"
    def configname = "config-${key}"

    def c = project.configurations.create(configname)
    c.getDependencies().add(d)

    def task = task "task-${key}"(type: Copy) {
      into "build/dependencies/${d.ext.exportTo}"
      from c
    }
    project.tasks.add(task)
    copyRuntimeLibs.dependsOn task
  }
}
</code></pre>

<p>So the dynamic tasks is executed, however nothing is copied. When I add a 'eachFiles' to debug, it doesn't go there.</p>

<p>Any clue?</p>