spring_reference/VIII. Build tool plugins/59.3. Default exclude rules.md

34 lines
1.4 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

### 59.3. 默认排除规则
Gradle处理"exclude rules"的方式和Maven稍微有些不同在使用starter POMs时这可能会引起无法预料的结果。特别地当一个依赖可以通过不同的路径访问时对该依赖声明的exclusions将不会生效。例如如果一个starter POM声明以下内容
```xml
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>4.0.5.RELEASE</version>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.0.5.RELEASE</version>
</dependency>
</dependencies>
```
`commons-logging` jar不会被Gradle排除因为通过没有`exclusion`元素的`spring-context`可以传递性的拉取到它spring-context → spring-core → commons-logging
为了确保正确的排除被实际应用Spring Boot Gradle插件将自动添加排除规则。所有排除被定义在`spring-boot-dependencies` POM并且针对"starter" POMs的隐式规则也会被添加。
如果不想自动应用排除规则,你可以使用以下配置:
```gradle
springBoot {
applyExcludeRules=false
}
```