[英]Gradle build: Exclude resources files from Spring Boot Jar file
我想从 jar 文件中排除所有配置文件,因为它们将在配置时提供,并且在构建路径中具有不同的版本可能会产生一些运行时问题。 我正在使用以下 Gradle 构建脚本,但出于某种原因,我仍然可以看到资源目录中存在的任何内容被复制到构建的 Jar 中。这意味着由于某种原因,提供的 Gradle 构建没有按预期工作。
apply plugin: 'distribution'
distributions {
main {
baseName = "${project.name}"
contents {
into('/conf'){
from('src/main/resources')
exclude("application.yml")
}
into('/lib'){
from('build/libs')
}
into('/bin'){
from('../bin')
}
}
}
}
processResources {
# Not sure how I need to point to the resources, so I included both. However, none is working.
exclude('resources/*')
exclude('src/main/resources/*')
}
bootJar{
# Not sure how I need to point to the resources, so I included both. However, none is working.
exclude('resources/*')
exclude('src/main/resources/*')
}
distTar {
dependsOn bootJar
}
tasks.withType(Tar) {
compression = Compression.GZIP
extension = "tar.gz"
}
configurations {
customArch
}
artifacts {
customArch file(distTar.archivePath)
}
通过使用processResources.enabled = false
,我能够排除资源使其不显示在Jar文件中,因此构建文件如下。
apply plugin: 'distribution'
distributions {
main {
baseName = "${project.name}"
contents {
into('/conf'){
from('src/main/resources')
exclude("application.yml")
}
into('/lib'){
from('build/libs')
}
into('/bin'){
from('../bin')
}
}
}
}
processResources.enabled = false
distTar {
dependsOn bootJar
}
tasks.withType(Tar) {
compression = Compression.GZIP
extension = "tar.gz"
}
configurations {
customArch
}
artifacts {
customArch file(distTar.archivePath)
}
我发现这个解决方案对我有用:
processResources {
exclude('logback-spring.xml')
}
...其中logback-spring.xml
位于src/main/resources
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.