如何在gradle中复制依赖库库JAR [英] how to copy the dependencies libraries JARs in gradle

查看:1757
本文介绍了如何在gradle中复制依赖库库JAR的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个可运行的jar与这个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',
' qos.logback:logback-core:1.0.6',
'org.slf4j:slf4j-api:1.6.0',
'junit:junit:4. +'

}

但它运行失败,因为依赖jar不能找到。



然后我添加这个代码:

 任务copyToLib {
into$ buildDir / output / libs
from configurations.runtime
}


b $ b

但没有什么改变...我找不到文件夹输出/ libs ...



如何将依赖libs jars复制到指定文件夹或路径?

解决方案

添加:



< build.dependsOn(copyToLib)

运行,Gradle构建任务和任何依赖它的任务(由 dependsOn 声明)。没有设置 build.dependsOn(copyToLib),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. +'

}

build.dependsOn(copyToLib)

任务copyToLib(类型:复制){
到$ buildDir / output / libs
从configurations.runtime
}


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?

解决方案

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.+'
    )
}

build.dependsOn(copyToLib)

task copyToLib(type: Copy) {
    into "$buildDir/output/libs"
    from configurations.runtime
}

这篇关于如何在gradle中复制依赖库库JAR的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆