Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 (         'commons-codec:commons-codec:1.6',         'commons-logging:commons-logging:1.1.1',         'org.apache.httpcomponents:httpclient:4.2.1',         'org.apache.httpcomponents:httpclient:4.2.1',         'org.apache.httpcomponents:httpcore:4.2.1',         'org.apache.httpcomponents:httpmime:4.2.1',         'ch.qos.logback:logback-classic:1.0.6',         'ch.qos.logback:logback-core:1.0.6',         'org.slf4j:slf4j-api:1.6.0',         'junit:junit:4.+'     ) } 

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?

like image 616
jychan Avatar asked Feb 03 '13 05:02

jychan


1 Answers

Add:

build.dependsOn(copyToLib) 

When gradle build runs, Gradle builds tasks and whatever tasks depend on it (declared by dependsOn). Without setting build.dependsOn(copyToLib), Gradle will not associate the copy task with the build task.

So:

apply plugin: 'java' apply plugin: 'application'  manifest.mainAttributes('Main-Class': 'com.test.HelloWorld')  repositories {     mavenCentral() }  dependencies {     compile (         'commons-codec:commons-codec:1.6',         'commons-logging:commons-logging:1.1.1',         'org.apache.httpcomponents:httpclient:4.2.1',         'org.apache.httpcomponents:httpclient:4.2.1',         'org.apache.httpcomponents:httpcore:4.2.1',         'org.apache.httpcomponents:httpmime:4.2.1',         'ch.qos.logback:logback-classic:1.0.6',         'ch.qos.logback:logback-core:1.0.6',         'org.slf4j:slf4j-api:1.6.0',         'junit:junit:4.+'     ) }  task copyToLib(type: Copy) {     into "${buildDir}/output/libs"     from configurations.runtime }  build.dependsOn(copyToLib) 
like image 180
xielingyun Avatar answered Nov 09 '22 21:11

xielingyun