Exclude file from named directory


(prantorbora) #1

Hi All, How do I exclude a file under a specific directory?

For example suppose I have two files(x.txt) under two root folder src and conf.

conf/a/b/c/some_unknown_folder/x.txt src/a1/b1/c1/some_unknown_folder/x.txt

If I only want my jar to include x.txt from “src” but not from “conf”, how do I do it without specifying the full path in exclude. I tried “from” with “exclude” methods but it is not working.

Thanks, PB


(Peter Niederwieser) #2

Are ‘src’ and ‘conf’ declared as source and/or resource directories, or are they just arbitrary directories? Why is specifying the full path not an option? Do you mean absolute path?


(prantorbora) #3

Src and conf are source and resource folders.

Thanks, PB


(Peter Niederwieser) #4

Then I don’t understand how the text file in the source folder makes it into the Jar. Can you post the relevant parts of your build script?


(prantorbora) #5

The text file was just an example, it could be any file type. Also src and conf was just an example, it could be two source folder(src, generated-src, external-src). For example I want to say from generated-src exclude files A,B,C but if such files exist in src or external-src allow it.

Thanks, PB

Thanks, Prantor


(Peter Niederwieser) #6

Do you directly add files to the Jar (task), or is it all controlled via source sets?


(prantorbora) #7

It is controlled through source sets.


(Peter Niederwieser) #8

Then it’s usually best to add includes/excludes at the source (directory) set level. Note that it isn’t currently possibly to specify includes/excludes at the directory level but only at the source directory set level (e.g. ‘sourceSets.main.java { include “some/pkg/Foo.java” }’).