'How to exclude all files under a directory in Gradle?
packagingOptions {
exclude 'org/apache/commons/codec/language/bm/gen_approx_portuguese.txt'
}
For example, this one will exclude 1 file. But how to exclude all file under a directory?
like:
org/apache/commons/codec/language/bm/
folder?
. does not work :)
Solution 1:[1]
wild card can be used to enforce action to multiple file in directory. See this:-
packagingOptions {
exclude 'org/apache/commons/codec/language/bm/*'
}
You can also exclude a file/directory with out specifying the full path this way:-
packagingOptions {
exclude '**/language/bm/*'
}
Note: this will exclude any language/bm/
any where in the path
Solution 2:[2]
This is for Kotlin DSL (build.gradle.kts) and AGP (Android Gradle Plugin) version 7.0.0 and newer:
android {
// ...
packagingOptions {
resources.excludes += "org/apache/commons/codec/language/bm/*"
// OR
// resources.excludes += setOf(
// "org/apache/commons/codec/language/bm/*"
// )
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | ambes |
Solution 2 |