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?
repositories { flatDir { dirs("lib") } flatDir { dirs("lib1", "lib2") } } This adds repositories which look into one or more directories for finding dependencies. This type of repository does not support any meta-data formats like Ivy XML or Maven POM files.
Gradle declares dependencies on JAR files inside your project's module_name /libs/ directory (because Gradle reads paths relative to the build.gradle file).
When it comes to managing dependencies, both Gradle and Maven can handle dynamic and transitive dependencies, to use third-party dependency caches, and to read POM metadata format. You can also declare library versions via central versioning definition and enforce central versioning.
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'
}
the dependency configuration of compile is deprecated in gradle 4.x. You need to replace that with default. So the above code-snippet becomes:
dependencies {
implementation 'com.google.inject:guice:4.0-beta5'
}
task copyDependencies(type: Copy) {
from configurations.default
into 'dependencies'
}
This is the equivalent Kotlin DSL version (added the buildDir prefix to make it copy the dependencies in the build folder):
task("copyDependencies", Copy::class) {
from(configurations.default).into("$buildDir/dependencies")
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With