Gradle fileTree exclude all except certain directories

血红的双手。 提交于 2021-01-27 07:22:39

问题


I am using the fileTree utility to get a list of files but need to exclude all directories except a select few from the list.

My directory structure:

node_modules/
    react-native/
    react/
    third-party-package/
    another-package/

I need to exclude all directories except the ones named react-native and react.

Currently I am excluding all node_modules, but this is not what I want...

fileTree(dir: '.', excludes: [ 'node_modules/**'] )

How would I do this with the fileTree?


回答1:


You can use a closure for this. Something like this:

fileTree(dir: '.').exclude {details ->
    (details.file.canonicalPath.contains("node_modules")
            && !details.file.canonicalPath.contains('react'))}

You can provide your own condition for files, you want to exlude. Here is a simpliest one, where the files paths are checked, whether they contain node_modules and not react and if condition is true, this files are excluded.

Sure, you have to make it more specific, but you are free to provide any condition for you requirements.



来源:https://stackoverflow.com/questions/38207029/gradle-filetree-exclude-all-except-certain-directories

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!