我的gradle模块具有以下文件夹结构:
src
main
application
META-INF
application.xml
was.policy
was.webmodule
java
resources
image.bmp
logback.xml
... other files, properties
webapp
我的目标是建立一个仅包含Tclient.war和META-INF的Ear存档。但是,gradle会将所有资源文件复制到耳根。
有关Ear Plugin的分级文档说:
Ear任务的默认行为是复制以下内容: src / main / application到存档的根目录。如果您的申请 目录不包含META-INF / application.xml部署 描述符,然后将为您生成一个。
因此,目前尚不清楚为什么将资源置于根源。也许它的工作就像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)
....
}
答案 0 :(得分:0)
可能的解决方法是从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')
}
但是,我发现此解决方法有点难看,这是一个肮脏的骇客。