gpt4 book ai didi

Gradle Ear 插件不应将资源复制到 .ear 根目录

转载 作者:行者123 更新时间:2023-12-03 05:23:14 28 4
gpt4 key购买 nike

我的 gradle 模块具有以下文件夹结构:

src
main
application
META-INF
application.xml
was.policy
was.webmodule
java
resources
image.bmp
logback.xml
... other files, properties
webapp
我的目标是建立一个 ear 文件,它只包含 Tclient.war 和 META-INF。但是,gradle 会将所有资源文件复制到 ear 根目录。
关于 Ear Plugin 的 Gradle 文档说:

The default behavior of the Ear task is to copy the content ofsrc/main/application to the root of the archive. If your applicationdirectory doesn’t contain a META-INF/application.xml deploymentdescriptor then one will be generated for you.


因此,目前还不清楚为什么它将资源放入根目录。也许,它就像 org.gradle.api.tasks.bundling.Jar任务,我应该以某种方式覆盖这种行为?
这是我的部分 build.gradle 文件:
jar {
description 'Creates tclient.jar'
archiveBaseName = 'tclient'
destinationDirectory = file('src/main/webapp/WEB-INF/lib')
from sourceSets.main.output
include '**/*'
include '**/*.properties'
include '**/*.cmd'
}

ear{
description = "Ear archive for WebSphere server"
archiveBaseName = 'Tclient'
appDirName('src/main/application')

// workaround to exclude classes from ear root
rootSpec.exclude('**/de/**')
rootSpec.exclude('**/org/**')
}

war {
archiveFileName = 'Tclient.war'
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
webInf {
from configurations.natives into 'lib/bin'
}

// do not put compiled classes inside WEB-INF/classes
rootSpec.exclude('**/de/**')
rootSpec.exclude('**/org/**')
rootSpec.exclude('urlrewrite*.dtd')

from(jar) {
into 'WEB-INF/lib'
}

}


dependencies {
// Place .war inside .ear root
deploy files(war)
....
}

最佳答案

可能的解决方法是从 rootspec 中排除冗余资源:

ear{
description = "Ear archive for WebSphere server"
archiveBaseName = 'Tclient'
appDirName('src/main/application')

// workaround to exclude classes from ear root
rootSpec.exclude('**/de/**')
rootSpec.exclude('**/org/**')

// workaround
rootSpec.exclude('*.properties')
rootSpec.exclude('*.xml')
rootSpec.exclude('*.dtd')
rootSpec.exclude('*.bmp')
}
但是,我发现这种解决方法有点难看,而且是一种肮脏的技巧。

关于Gradle Ear 插件不应将资源复制到 .ear 根目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62712979/

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