[英]Exclude all compiled classes from jar built by gradle java project
I have a gradle java project with custom task which generates some files during build. 我有一个带有自定义任务的gradle Java项目,该项目在构建期间会生成一些文件。 I need to produce jar artifact containing ONLY generated files. 我需要产生仅包含生成文件的jar工件。 Problem: jar contains both generated files and class files . 问题: jar同时包含生成的文件和类文件 。
Exclusion of *.java files from source sets is impossible because I need compiled classes for generation. 从源集中排除* .java文件是不可能的,因为我需要生成的编译类。
jar {
exclude("**/*.class")
from ("$buildDir/generated-files-dir")
}
Snippet above removes class files but leaves directories as is. 上面的代码段删除了类文件,但保留了目录。
Add includeEmptyDirs = false
to your jar task. 将includeEmptyDirs = false
添加到jar任务。
jar {
exclude("**/*.class")
includeEmptyDirs = false
from ("$buildDir/generated-files-dir")
}
https://docs.gradle.org/current/dsl/org.gradle.api.tasks.bundling.Jar.html#org.gradle.api.tasks.bundling.Jar:includeEmptyDirs https://docs.gradle.org/current/dsl/org.gradle.api.tasks.bundling.Jar.html#org.gradle.api.tasks.bundling.Jar:includeEmptyDirs
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.