[英]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.