gpt4 book ai didi

java - Gradle构建:从Spring Boot Jar文件中排除资源文件

转载 作者:行者123 更新时间:2023-12-03 03:17:35 27 4
gpt4 key购买 nike

我想从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)
}

关于java - Gradle构建:从Spring Boot Jar文件中排除资源文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56624607/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com