Gradle 不排除指定文件
Gradle not excluding specified file
我已经添加了 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')
}
您正试图从源目录中排除 class 文件,但只有您的 Java(source) 文件驻留在该目录中。您是要阻止构建 class 还是不打包?排除 java 文件以防止构建它,或者从输出目录而不是源目录中排除 class 文件。
经过反复试验,我终于能够从我的 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"
}
}
我已经添加了 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')
}
您正试图从源目录中排除 class 文件,但只有您的 Java(source) 文件驻留在该目录中。您是要阻止构建 class 还是不打包?排除 java 文件以防止构建它,或者从输出目录而不是源目录中排除 class 文件。
经过反复试验,我终于能够从我的 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"
}
}