gradle repository points to local directory with m

2019-05-09 23:26发布

问题:

I have question regarding the build dependencies in the build.gradle for the local repository (i.e. using the local directory)

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
}

Does it solve the dependencies in the libs directory only or it is resolves the dependencies on all the subfolders of lib directory? If it does not resolve the dependencies of subfolders/subdirectories, how to resolve the dependencies?

Note: Our project depends on lot of jars files(instead of giving the full file name for each jars/libs), so wants to know any alternate way.

回答1:

It should depend on what pattern is passed. fileTree is defined on Project and returns an instance of ConfigurableFileTree. As you can see, one of ConfigurableFileTree super-interfaces is PatternFilterable which has patterns well documented e.g.:

 all files ending with 'jsp' (including subdirectories)
    **/*.jsp

So I guess to include subdirectories you just need to change the pattern:

dependencies {
    compile fileTree(include: ['**/*.jar'], dir: 'libs')
}

In general ant-style patterns are used:

A PatternFilterable represents some file container which Ant-style include and exclude patterns or specs can be applied to.