简体   繁体   中英

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. I need to produce jar artifact containing ONLY generated files. Problem: jar contains both generated files and class files .

Exclusion of *.java files from source sets is impossible because I need compiled classes for generation.

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM