We have a package that is related to some requirements that were removed, but we don\'t want to necessarily delete the code because there\'s a possibility it will be needed
This solution is valid if you don´t want to compile these packages, but if you want to compile them and exclude from your JAR you could use
// tag::jar[]
jar {
exclude('mi/package/excluded/**')
exclude('mi/package/excluded2/**')
}
// end::jar[]
In 2018:
You may also use a closure or Spec to specify which files to include or exclude. The closure or Spec is passed a FileTreeElement, and must return a boolean value.
jar {
exclude {
FileSystems.getDefault()
.getPathMatcher("glob:com/ourcompany/someotherpackage/polling/**")
.matches(it.file.toPath())
}
}
See Jar.exclude, FileTreeElement and Finding Files.
If you have some sources that you don't want to be compiled, you have to declare a filter for the sources, not for the class files that are put in the Jar. Something like:
sourceSets {
main {
java {
include 'com/ourcompany/somepackage/activityadapter/**'
include 'com/ourcompany/someotherpackage/**'
exclude 'com/ourcompany/someotherpackage/polling/**'
}
}
}