gradle-如何从战争中排除WEB-INF/classs [英] gradle - how to exclude WEB-INF/classes from war
问题描述
我有一个非常简单的要求.我有以下项目布局:
I have a fairly simple requirement. I have the following project layout:
project/build.gradle
--src/main/java
--src/main/res
我想做的是为project/src/main/java
将此 jar 文件包含在 war 中,然后将WEB-INF/classes
从 war 文件中排除
Include this jar file in the war and then exclude the WEB-INF/classes
from the war file
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'jetty'
apply plugin: 'war'
dependencies {
..
compile 'com.fasterxml.jackson.core:jackson-core:2.3.0'
compile 'com.fasterxml.jackson.core:jackson-databind:2.3.0'
..
}
jar {
archiveName = 'hello.jar'
}
war {
dependsOn jar
archiveName = 'hello.war'
classpath fileTree(dir:'build/libs/',include:'*.jar')
classpath configurations.compile
webInf {
from ('src/main/res') {
include '**/*.*'
into 'resources/'
}
}
}
我尝试了各种方法来排除WEB-INF/classes
,包括以下代码段:
I have tried various things to exclude WEB-INF/classes
including the following snippets:
使用 rootSpec.exclude :
war {
dependsOn jar
archiveName = 'hello.war'
classpath fileTree(dir:'build/libs/',include:'*.jar')
classpath configurations.compile
rootSpec.exclude ('WEB-INF/classes')
...
}
使用 classpath :
war {
dependsOn jar
archiveName = 'hello.war'
classpath fileTree(dir:'build/libs/',include:'*.jar')
classpath configurations.compile
classpath fileTree(dir:'build/classes/', exclude:'*.class')
...
}
从('war')
使用:
war {
dependsOn jar
archiveName = 'hello.war'
classpath fileTree(dir:'build/libs/',include:'*.jar')
classpath configurations.compile
from ('war') {
exclude('WEB-INF/classes')
}
}
直接进行排除":
war {
dependsOn jar
archiveName = 'hello.war'
classpath fileTree(dir:'build/libs/',include:'*.jar')
classpath configurations.compile
exclude('WEB-INF/classes')
...
}
我在网上找到了所有建议-但似乎都没有用.任何想法我做错了.
Which were all the suggestions I found online - but none of them seems to work. Any ideas what I am doing wrong.
以下是我找到的一些文章和代码的链接: 等级:战争任务具有冲突的包含/排除
Here are links to some of the articles and code I found: Gradle: War Task has Conflicting Includes/Excludes
https://github.com/veny/smevente/blob/master /build.gradle
The gradle version is 2.12.
推荐答案
以下是对我有用的方法,但是您仍然会在战争捆绑包中看到一个(无害的)空包装:
Below is what worked for me, but you will still see an (harmless) empty package in the war bundle:
war {
rootSpec.exclude('**/com/xxxxx/web/client/')
}
这篇关于gradle-如何从战争中排除WEB-INF/classs的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!