How to copy the dependencies libraries JARs in gradle

i got a runnable jar with this build.gradle

apply plugin: ‘java’ apply plugin: ‘application’

manifest.mainAttributes(“Main-Class” : “com.test.HelloWorld”)

repositories {

mavenCentral() }

dependencies {

compile (











) } but it run failed, because the dependencies jars can’t find.

and then i add this code:

task copyToLib(type: Copy) {

into “$buildDir/output/libs”

from configurations.runtime }

but nothing change…i can’t find the folder output/libs…

how can i copy the dependencies libs jars to a specified folder or path?

How do you run the code?

PS: Please enclose code in HTML ‘code’ tags. PPS: Please don’t double-post here and on Stack Overflow.

gradle build

That won’t run the code. Can you tell me what exactly you typed, and what exact error message you got?

first i run: gradle build, get the runnable jar file then ,run the jar file: java -jar XXX.jar

That’s not how it works. Try ‘gradle run’ or ‘gradle distZip’. For more information, see the Gradle User Guide.

i need write it in the build.gradle file, because it is one of the jobs

I don’t understand what you are saying.

simply put, i need to write a build.gradle, it can get a runnable file, and copy the dependencies JARs to a folder(not a zip\tar file). i don’t know how to copy the jars.

What’s the problem with your ‘copyToZip’ task? Looks just fine. You could also use ‘gradle installApp’ (see user guide).

if using zip, i need to unzip the it before run the runnable jar

What I meant is what the problem with your ‘copyToLib’ task is.

about the copyToLib task, it does not work, because i can’t find the folder “output/libs”

Look in ‘build/output/libs’.

no the ouput folder in the build.

Sorry, I don’t understand what you want. I recommend to check out the Gradle user guide. Good luck!