我已经添加了exclude
语句,但我的排除abc/object/MyTestConfig*.class
仍然被添加到jar中,有什么原因吗?
jar {
zip64 true
from((configurations.compile - configurations.jarDepends).collect { it.isDirectory() ? it : zipTree(it) }) {
exclude "META-INF/*.SF"
exclude "META-INF/*.DSA"
exclude "META-INF/*.RSA"
}
from ("$projectDir/src/main/java/") {
include "**/*.hbm.xml",
"abc/tools/xml/XMLClasses.MF"
exclude "abc/object/MyTestConfig*.class"
}
}
task filterVersionConstants(type: Copy) {
from "src/main/java/abc/"
into "src/main/java/abc/"
include "VersionConstants.tmpl"
exclude "**/MyTestConfig*.class"
rename { String fileName ->
fileName.replace('.tmpl', '.java')
}
您正在尝试从源目录中排除类文件,但只有您的 Java(源(文件驻留在该目录中。您是试图阻止构建类,还是只是不打包?排除 java 文件以防止其生成,或者从输出目录而不是源目录中排除类文件。
经过几次反复试验,终于我能够从我的 jar 中排除这个文件,如下所示。基本上,我首先需要在jar
任务中提取排除语句。
jar {
zip64 true
exclude "abc/object/MyTestConfig*.class"
from((configurations.compile - configurations.jarDepends).collect { it.isDirectory() ? it : zipTree(it) }) {
exclude "META-INF/*.SF"
exclude "META-INF/*.DSA"
exclude "META-INF/*.RSA"
}
from ("$projectDir/src/main/java/") {
include "**/*.hbm.xml",
"abc/tools/xml/XMLClasses.MF"
}
}