gradle排除指定依赖
时间: 2023-10-07 22:11:26 浏览: 66
在 Gradle 中,可以使用 `exclude` 关键字来排除指定依赖。例如,如果你想在项目中排除 `com.google.guava:guava` 依赖,可以在 build.gradle 文件中这样写:
```groovy
dependencies {
implementation('com.example:mylibrary:1.0') {
exclude group: 'com.google.guava', module: 'guava'
}
}
```
这将从 `com.example:mylibrary:1.0` 中排除 `com.google.guava:guava` 依赖。你也可以排除多个依赖,只需要在 `exclude` 中添加多个参数即可。例如:
```groovy
dependencies {
implementation('com.example:mylibrary:1.0') {
exclude group: 'com.google.guava', module: 'guava'
exclude group: 'commons-io', module: 'commons-io'
}
}
```
这将从 `com.example:mylibrary:1.0` 中排除 `com.google.guava:guava` 和 `commons-io:commons-io` 依赖。
相关问题
gradle排除间接依赖中指定的类
在 Gradle 中,我们可以使用 `exclude` 方法来排除依赖中的指定类。例如,假设我们有以下依赖关系:
```
implementation 'com.example:library-a:1.0.0'
implementation 'com.example:library-b:1.0.0'
```
其中 `library-b` 依赖于 `library-a`,并且我们想要排除 `library-a` 中的 `SomeClass` 类,可以在 `library-b` 的依赖声明中添加 `exclude` 方法:
```
implementation('com.example:library-b:1.0.0') {
exclude group: 'com.example', module: 'library-a'
exclude module: 'SomeClass'
}
```
这将从 `library-b` 的依赖中排除 `com.example:library-a` 以及其中的 `SomeClass` 类。注意,我们可以使用 `group` 和 `module` 属性来精确指定要排除的依赖项,也可以仅使用 `module` 属性来指定要排除的类。
gradle排除不在build.gradle中配置的依赖,也就是依赖的依赖中指定的类
可以使用Gradle的exclude属性来排除不需要的依赖。exclude属性可以在dependencies块中指定,格式为:
```
compile('group:name:version') {
exclude group: 'unwanted_group', module: 'unwanted_module'
}
```
其中,group和module分别指定需要排除的依赖的组和模块名称。如果需要排除多个依赖,可以使用多个exclude语句。
例如,如果要排除jackson-databind中的com.fasterxml.jackson.core:jackson-core依赖,可以这样配置:
```
compile('com.fasterxml.jackson.core:jackson-databind:2.9.8') {
exclude group: 'com.fasterxml.jackson.core', module: 'jackson-core'
}
```
这样,jackson-core依赖就不会被包含在项目中了。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)