java-我使用gradle构建了一个胖子罐,其中包含了我所有的依赖项.现在,当使用distZip时,如何排除这些jar文件?
作者:互联网
所以这是我的gradle脚本:
apply plugin: 'java'
apply plugin: 'application'
mainClassName = "com.company.diagnostics.app.client.AppMain"
dependencies {
compile ('commons-codec:commons-codec:1.8')
compile (libraries.jsonSimple)
compile ('org.apache.ant:ant:1.8.2')
compile project(":app-common")
testCompile 'org.powermock:powermock-mockito-release-full:1.6.2'
}
jar {
archiveName = "app-client.jar"
from {
configurations.runtime.collect {
it.isDirectory() ? it : zipTree(it)
}
configurations.compile.collect {
it.isDirectory() ? it : zipTree(it)
}
}
manifest {
attributes 'Main-Class': 'com.company.diagnostics.app.client.AppMain"'
}
exclude 'META-INF/*.SF', 'META-INF/*.DSA', 'META-INF/*.RSA', 'META-INF/*.MF'
}
构建后,它会生成一个可分发的zip,看起来像这样:
macbook-pro:distributions awt$tree
.
├── app-client
│ ├── bin
│ │ ├── app-client
│ │ └── app-client.bat
│ └── lib
│ ├── ant-1.8.2.jar
│ ├── ant-launcher-1.8.2.jar
│ ├── commons-codec-1.8.jar
│ ├── app-client.jar
│ ├── app-common.jar
│ ├── guava-17.0.jar
│ ├── jetty-2.0.100.v20110502.jar
│ ├── json-simple-1.1.2.jar
│ ├── osgi-3.7.2.v20120110.jar
│ ├── services-3.3.0.v20110513.jar
│ └── servlet-1.1.200.v20110502.jar
└── app-client.zip
因为我已经使用自己的自定义jar任务将依赖项捆绑到jar存档中,所以如何防止distZip再次捆绑这些jar文件?
- ant-1.8.2.jar
- ant-launcher-1.8.2.jar
- commons-codec-1.8.jar
- guava-17.0.jar
- jetty-2.0.100.v20110502.jar
- json-simple-1.1.2.jar
- osgi-3.7.2.v20120110.jar
- services-3.3.0.v20110513.jar
- servlet-1.1.200.v20110502.jar
之所以将它们捆绑到jar任务中,是因为它原本是一个独立的库.后来决定也应该具有命令行界面(因此,distZip并自动创建linux / mac / windows的包装脚本).它仍然需要作为一个独立的fatjar存在,并将所有依赖项捆绑在一起.我只是不需要/ libs中的多余内容.
如何获得distZip排除它们?
解决方法:
您可以修改distZip任务,以排除不想包含在分发存档中的库,例如:
distZip {
exclude 'ant-1.8.2.jar'
exclude 'ant-launcher-1.8.2.jar'
exclude 'commons-codec-1.8.jar'
exclude 'guava-17.0.jar'
exclude 'jetty-2.0.100.v20110502.jar'
exclude 'json-simple-1.1.2.jar'
exclude 'osgi-3.7.2.v20120110.jar'
exclude 'services-3.3.0.v20110513.jar'
exclude 'servlet-1.1.200.v20110502.jar'
}
或者可以通过applicationDistribution来提供,它为整个应用程序插件提供配置:
applicationDistribution.with {
exclude 'ant-1.8.2.jar'
exclude 'ant-launcher-1.8.2.jar'
exclude 'commons-codec-1.8.jar'
exclude 'guava-17.0.jar'
exclude 'jetty-2.0.100.v20110502.jar'
exclude 'json-simple-1.1.2.jar'
exclude 'osgi-3.7.2.v20120110.jar'
exclude 'services-3.3.0.v20110513.jar'
exclude 'servlet-1.1.200.v20110502.jar'
}
您可以尝试将排除更改为包含以使文件列表更短,或者尝试将排除绑定到依赖列表.
标签:gradlew,build-gradle,gradle,build,java 来源: https://codeday.me/bug/20191119/2037248.html