我当前的build.gradle如下所示。
repositories {
flatDir {
dirs 'lib'
}
maven {
mavenCentral()
}
dependencies {
compile "commons-logging:commons-logging:1.0.4",
"org.apache.httpcomponents:httpclient:4.4",
"org.apache.httpcomponents:httpcore:4.4",
"com.fasterxml.jackson.core:jackson-annotations:2.5.1",
"joda-time:joda-time:2.7",
compile files('../lib/abc.jar')
}
jar {
manifest{
attributes ("Version" : project.version, "${parent.manifestSectionName}")
attributes ("Name" : project.name, "${parent.manifestSectionName}")
}
from {
configurations.runtime.filter( {! (it.name =~ /abc.*\.jar/ )}).collect {
it.isDirectory() ? it : zipTree(it)
}
}
}
因为你可以看到我在运行时删除了abc.jar,但同样的方法我想删除更多的jar。 总之,我想在胖罐里面放几个罐子,需要排除少量。 那我怎么能实现呢?
答案 0 :(得分:0)
以下示例可能对您有所帮助。您需要添加新配置 - 它默认情况下 extends 编译,因此它将在开发期间可用,但不会包含在生成的jar中 - 在下面的示例中为joda。
apply plugin: 'java'
repositories {
mavenCentral()
}
configurations {
lol
}
dependencies {
compile "commons-logging:commons-logging:1.0.4",
"org.apache.httpcomponents:httpclient:4.4",
"org.apache.httpcomponents:httpcore:4.4",
"com.fasterxml.jackson.core:jackson-annotations:2.5.1"
lol "joda-time:joda-time:2.7"
}
jar {
from {
configurations.runtime.collect {
it.isDirectory() ? it : zipTree(it)
}
}
}