[英]Java Gradle: How to include external jars using java-plugin jar task?
apply plugin: 'java'
archivesBaseName = 'foo-client'
sourceCompatibility = JavaVersion.VERSION_1_7
targetCompatibility = JavaVersion.VERSION_1_7
//version = '1.0'
dependencies{
compile 'foo:bar:1.0-SNAPSHOT',
'foo:bar-common:1.0-SNAPSHOT',
'foo:bar-communication-api:1.0-SNAPSHOT'
}
repositories{
flatDir{
dirs '/lib'
}
}
When executing the inherited jar
task, this will create foo-client.jar
in the build/lib
directory of the project. 执行继承的
jar
任务时,这将在项目的build/lib
目录中创建foo-client.jar
。 What I need to do is include several jars to be put in that same directory, otherwise the project will not run correctly. 我需要做的是在同一个目录中放入几个jar,否则该项目将无法正常运行。
How can I do this? 我怎样才能做到这一点?
You could define the external jars as runtime dependencies and then use a copy task to copy them to build/lib, eg: 您可以将外部jar定义为运行时依赖项,然后使用复制任务将其复制到build / lib,例如:
task copyLibs(type: Copy) {
from configurations.runtime
into "$buildDir/libs"
}
Using Gradle 1.1 the following did the trick, 使用Gradle 1.1可以达到以下目的:
apply plugin: 'java'
archivesBaseName = 'foo-client'
sourceCompatibility = JavaVersion.VERSION_1_7
targetCompatibility = JavaVersion.VERSION_1_7
task copyToLib(type: Copy){
into 'bar\\lib'
from configurations.runtime
from configurations.default.allArtifacts.getFiles()
}
dependencies{
compile 'foo:bar-agent-dist:2.0.0-SNAPSHOT',
'foo:bar-common:2.0.0-SNAPSHOT',
'foo:bar-communication-api:2.0.0-SNAPSHOT'
}
repositories{
flatDir{
dirs '/lib'
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.