mavengradledependency-management

Gradle equivalent to Maven's "copy-dependencies"?


In Maven-land, anytime I want to simply pull down the transitive dependencies for a particular POM file, I just open a shell, navigate to where the POM is located, and run:

mvn dependency:copy-dependencies

And boom, Maven creates a target/ directory inside the current one and places all the transitively-fetched JARs to that location.

I am now trying to make the switch over to Gradle, but Gradle doesn't seem to have the same feature. So I ask: Does Gradle have an equivalent to Maven's copy-dependencies? If so, can someone provide an example? If not, would other devs find this to be a worthwhile contribution to the Gradle community?


Solution

  • There's no equivalent of copy-dependencies in gradle but here's a task that does it:

    apply plugin: 'java'
    
    repositories {
       mavenCentral()
    }
    
    dependencies {
       compile 'com.google.inject:guice:4.0-beta5'
    }
    
    task copyDependencies(type: Copy) {
       from configurations.compile
       into 'dependencies'
    }
    

    Is it worthwhile to do a contribution? AS You can see it's really easy to do, so I don't think so.

    EDIT

    From gradle 4+ it will be:

    task copyDependencies(type: Copy) {
      from configurations.default
      into 'dependencies'
    }