How to copy the dependencies libraries JARs in gradle

(415683089) #1

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?

(Peter Niederwieser) #2

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.

(415683089) #3

gradle build

(Peter Niederwieser) #4

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

(415683089) #5

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

(Peter Niederwieser) #6

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

(415683089) #7

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

(Peter Niederwieser) #8

I don’t understand what you are saying.

(415683089) #9

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.

(Peter Niederwieser) #10

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

(415683089) #11

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

(Peter Niederwieser) #12

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

(415683089) #13

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

(Peter Niederwieser) #14

Look in ‘build/output/libs’.

(415683089) #15

no the ouput folder in the build.

(Peter Niederwieser) #16

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