[英]gradle - how to exclude WEB-INF/classes from war
我有一个相当简单的要求。 我有以下项目布局:
project/build.gradle
--src/main/java
--src/main/res
我想做的是为project/src/main/java
所有 java 文件创建一个 jar
在war中包含这个jar文件,然后从war文件中排除WEB-INF/classes
build.gradle
看起来如下: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
包括以下片段:
使用rootSpec.exclude :
war {
dependsOn jar
archiveName = 'hello.war'
classpath fileTree(dir:'build/libs/',include:'*.jar')
classpath configurations.compile
rootSpec.exclude ('WEB-INF/classes')
...
}
使用类路径:
war {
dependsOn jar
archiveName = 'hello.war'
classpath fileTree(dir:'build/libs/',include:'*.jar')
classpath configurations.compile
classpath fileTree(dir:'build/classes/', exclude:'*.class')
...
}
使用 from ('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')
...
}
这是我在网上找到的所有建议 - 但似乎没有一个有效。 任何想法我做错了什么。
以下是我找到的一些文章和代码的链接: Gradle: War Task has Conflicting Includes/Excludes
https://github.com/veny/smevente/blob/master/build.gradle
gradle版本是2.12 。
以下是对我有用的内容,但您仍会在 war 包中看到一个(无害的)空包:
war {
rootSpec.exclude('**/com/xxxxx/web/client/')
}
我查看了文章,此代码有效:
from 'src/main/webapp/WEB-INF/classes'
exclude '**/*.class'
你对大量的反复试验是正确的。 这对我有用:
战争{
...
/* We bundle as a jar so that we can sign the jar.
* So, we exclude our separate class files.
*/
rootSpec.exclude('**/com/**')
// include our jar file
classpath fileTree(dir:"${project.buildDir}/libs/",include:project.YourJarFileNm)
...
}
from("./"){
includes = [
"a.log",
"b.properties","src/**"
]
into 'WEB-INF/'
}
excludes = [
"WEB-INF/misc/**"
]
这对我有用,可以从 WEB-INF 中排除类文件夹
war{
classpath = fileTree('*').exclude('**/classes')
}
我从http://gradle.1045684.n5.nabble.com/Exclude-properties-file-from-war-td3365147.html得到这个
你可以试试这个。
war {
enabled = true
classpath = classpath - sourceSets.main.output
from (jar) {
into 'WEB-INF/classes'
}
}
https://discuss.gradle.org/t/war-task-should-allow-bundling-classes-into-jar/491
这对我有用:
war {
dependsOn jar
archiveName = 'hello.war'
classpath = jar
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.