如何在 gradle 中复制依赖库 JAR [英] how to copy the dependencies libraries JARs in gradle
本文介绍了如何在 gradle 中复制依赖库 JAR的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我用这个 build.gradle 得到了一个可运行的 jar
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.
然后我添加以下代码:
task copyToLib(type: Copy) {
into "$buildDir/output/libs"
from configurations.runtime
}
但没有任何改变...我找不到文件夹 output/libs...
but nothing change...i can't find the folder output/libs...
如何将依赖库 jar 复制到指定的文件夹或路径?
how can i copy the dependencies libs jars to a specified folder or path?
推荐答案
添加:
build.dependsOn(copyToLib)
当 gradle build
运行时,Gradle 构建任务以及任何依赖它的任务(由 dependsOn
声明).如果不设置 build.dependsOn(copyToLib)
,Gradle 不会将复制任务与构建任务关联起来.
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.
所以:
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)
这篇关于如何在 gradle 中复制依赖库 JAR的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文