How can I save all the dependent jars for a module to a directory? I have an application that runs in IntelliJ IDEA, but I want to run it on another computer so I need to copy all the JAR files there.
Firstly, please consider using Gradle (or Gradle Wrapper) to do such things like getting/downloading dependencies of a project on another computer. But if you need to copy dependencies for any other reason you can define a task similar to:
task copyDependencies(type: Copy) {
from configurations.runtime
into "lib"
}
When you run:
gradle copyDependencies
runtime dependencies will be copied to a lib/
folder.
build.gradle
apply plugin: 'groovy'
repositories {
mavenCentral()
}
dependencies {
compile 'org.codehaus.groovy:groovy-all:2.3.11'
compile group: 'com.fasterxml.jackson.core', name: 'jackson-core', version: '2.9.1'
compile group: 'com.h2database', name: 'h2', version: '1.4.196'
testCompile group: 'org.spockframework', name: 'spock-core', version: '1.1-groovy-2.4'
}
task copyDependencies(type: Copy) {
from configurations.runtime
into "lib"
}
Command:
gradle copyDependencies
And lib/
directory contains:
lib
├── groovy-all-2.3.11.jar
├── h2-1.4.196.jar
└── jackson-core-2.9.1.jar
As I mentioned earlier, please consider using Gradle Wrapper so you don't have to worry about if there is a Gradle distribution installed on another computer. As stated in the documentation you can easily add Gradle Wrapper and then you can run
./gradlew [task]
by using wrapper instead of Gradle installed on your OS. In your case running
./gradlew build
will download all dependencies and build the project. It's way better than copying dependencies manually, Gradle was invented to do it for us.
following solution worked for me
configurations.implementation.setCanBeResolved(true)
configurations.api.setCanBeResolved(true)
task copyDependencies(type: Copy) {
from configurations.implementation
into "libs"
}
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