Gradle fileTree排除除某些目录外的所有目录 [英] Gradle fileTree exclude all except certain directories

查看:106
本文介绍了Gradle fileTree排除除某些目录外的所有目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用fileTree实用程序来获取文件列表,但需要排除所有目录,但从列表中选择少数目录除外.

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.

我的目录结构:

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

我需要排除所有目录,除了名为react-native和react的目录.

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

当前我不包括所有的node_modules,但这不是我想要的...

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

fileTree(dir:'.',不包括:['node_modules/**'])

我将如何使用fileTree做到这一点?

How would I do this with the fileTree?

推荐答案

您可以为此使用闭包.像这样:

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'))}

您可以为要排除的文件提供自己的条件.这是最简单的一种,其中检查文件路径,是否包含 node_modules 而不包含 react ,并且如果条件为true,则排除此文件.

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.

这篇关于Gradle fileTree排除除某些目录外的所有目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆