Skip to content

Commit

Permalink
Gradle 依赖相关排查
Browse files Browse the repository at this point in the history
  • Loading branch information
zq99299 committed Mar 20, 2024
1 parent 823c0c5 commit 72d58c9
Show file tree
Hide file tree
Showing 3 changed files with 252 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/posts/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ module.exports = () => {
'others/014.md',
'others/015.md',
'others/016.md',
'others/017.md',
]
}
]
Expand Down
250 changes: 250 additions & 0 deletions docs/posts/others/017.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,250 @@
# Gradle 依赖相关排查

## 依赖树 dependencies
> 该知识在 [官方文档 - 查看和调试依赖关系](https://docs.gradle.org/current/userguide/viewing_debugging_dependencies.html) 中有说到
```bash
# 打印依赖树
./gradlew dependencies

+--- org.projectlombok:lombok -> 1.18.18
+--- org.springframework.boot:spring-boot-starter-web -> 2.4.3
| +--- org.springframework.boot:spring-boot-starter:2.4.3
| | +--- org.springframework.boot:spring-boot:2.4.3
| | | +--- org.springframework:spring-core:5.3.4
| | | | \--- org.springframework:spring-jcl:5.3.4
| | | \--- org.springframework:spring-context:5.3.4
| | | +--- org.springframework:spring-aop:5.3.4
| | | | +--- org.springframework:spring-beans:5.3.4
| | | | | \--- org.springframework:spring-core:5.3.4 (*)
| | | | \--- org.springframework:spring-core:5.3.4 (*)
...
(c) - dependency constraint
(*) - dependencies omitted (listed previously)

(n) - Not resolved (configuration is not meant to be resolved)
# 上面也告诉了,括号里面的 * 之类的是什么含义

```

- `(c)`:依赖约束(`dependency constraint`(这个知识我还没学会))
- `(*)`:省略的依赖项(之前已列出)
- `(n)` :未解析(配置不需要解析)
## 依赖洞察 dependencyInsight
> 该知识在 [官方文档 - 查看和调试依赖关系](https://docs.gradle.org/current/userguide/viewing_debugging_dependencies.html) 中有说到

最简单的使用方式使用 `--dependency <dependency>` 指令,比如说,在依赖树中看到这样一个信息:
```bash
#
+--- net.sf.ehcache:ehcache -> 2.10.6
| \--- org.slf4j:slf4j-api:1.7.25 -> 1.7.30
```
`slf4j-api`1.7.25 的版本,最后使用了 1.7.30 的版本,这是怎么回事?
```bash
# 语法
./gradlew dependencyInsight --dependency <dependency group:name 方式,或者其中一个>
```
在这里我们使用以下命令查看
```bash
./gradlew dependencyInsight --dependency org.slf4j:slf4j-api

org.slf4j:slf4j-api:1.7.30 (selected by rule)
variant "compile" [
org.gradle.status = release (not requested)
org.gradle.usage = java-api
org.gradle.libraryelements = jar (compatible with: classes)
org.gradle.category = library

Requested attributes not found in the selected variant:
org.gradle.dependency.bundling = external
org.gradle.jvm.version = 8
]
# 这是最后被选中的版本,可以看到是 spring-boot-starter-logging 里面依赖的
org.slf4j:slf4j-api:1.7.30
+--- org.slf4j:jul-to-slf4j:1.7.30
| \--- org.springframework.boot:spring-boot-starter-logging:2.4.3
| \--- org.springframework.boot:spring-boot-starter:2.4.3
| +--- org.springframework.boot:spring-boot-starter-web:2.4.3
| | \--- compileClasspath (requested org.springframework.boot:spring-boot-starter-web)
| +--- org.springframework.boot:spring-boot-starter-json:2.4.3
| | +--- compileClasspath (requested org.springframework.boot:spring-boot-starter-json)
| | \--- org.springframework.boot:spring-boot-starter-web:2.4.3 (*)
| +--- org.springframework.boot:spring-boot-starter-validation:2.4.3
| | \--- compileClasspath (requested org.springframework.boot:spring-boot-starter-validation)
| +--- org.springframework.boot:spring-boot-starter-security:2.4.3
| | \--- compileClasspath (requested org.springframework.boot:spring-boot-starter-security)
| +--- com.github.pagehelper:pagehelper-spring-boot-starter:1.3.0 (requested org.springframework.boot:spring-boot-starter:2.3.1.RELEASE)
| | \--- compileClasspath
| +--- org.springframework.boot:spring-boot-starter-quartz:2.4.3
| | \--- compileClasspath (requested org.springframework.boot:spring-boot-starter-quartz)
| +--- org.springframework.boot:spring-boot-starter-cache:2.4.3
| | \--- compileClasspath (requested org.springframework.boot:spring-boot-starter-cache)
| +--- org.mybatis.spring.boot:mybatis-spring-boot-starter:2.1.3 (requested org.springframework.boot:spring-boot-starter:2.3.0.RELEASE)
| | \--- com.github.pagehelper:pagehelper-spring-boot-starter:1.3.0 (*)
| +--- org.springframework.boot:spring-boot-starter-jdbc:2.4.3
| | +--- com.baomidou:mybatis-plus-boot-starter:3.4.2 (requested org.springframework.boot:spring-boot-starter-jdbc:2.3.2.RELEASE)
| | | \--- compileClasspath
| | \--- org.mybatis.spring.boot:mybatis-spring-boot-starter:2.1.3 (requested org.springframework.boot:spring-boot-starter-jdbc:2.3.0.RELEASE) (*)
| \--- org.springframework.boot:spring-boot-starter-actuator:2.4.3
| \--- cn.pomit:spring-boot-monitor:0.0.3 (requested org.springframework.boot:spring-boot-starter-actuator:2.0.4.RELEASE)
| \--- compileClasspath
+--- redis.clients:jedis:3.3.0
| \--- us.codecraft:webmagic-extension:0.7.5 (requested redis.clients:jedis:3.6.0)
| \--- compileClasspath
\--- us.codecraft:webmagic-core:0.7.5
+--- compileClasspath
\--- us.codecraft:webmagic-extension:0.7.5 (*)

# 这些包中的 slf4j-api 都从低版本使用了 高版本的
org.slf4j:slf4j-api:1.7.7 -> 1.7.30
\--- org.quartz-scheduler:quartz:2.3.2
\--- org.springframework.boot:spring-boot-starter-quartz:2.4.3
\--- compileClasspath (requested org.springframework.boot:spring-boot-starter-quartz)

org.slf4j:slf4j-api:1.7.22 -> 1.7.30
\--- io.swagger:swagger-models:1.5.22
+--- com.github.xiaoymin:knife4j-spring:2.0.9
| \--- com.github.xiaoymin:knife4j-spring-boot-autoconfigure:2.0.9
| \--- com.github.xiaoymin:knife4j-spring-boot-starter:2.0.9
| \--- compileClasspath
+--- io.springfox:springfox-swagger2:3.0.0 (requested io.swagger:swagger-models:1.5.20)
| +--- io.springfox:springfox-boot-starter:3.0.0
| | \--- compileClasspath
| \--- com.github.xiaoymin:knife4j-spring:2.0.9 (requested io.springfox:springfox-swagger2:2.10.5) (*)
\--- io.springfox:springfox-swagger-common:3.0.0 (requested io.swagger:swagger-models:1.5.20)
+--- io.springfox:springfox-oas:3.0.0
| \--- io.springfox:springfox-boot-starter:3.0.0 (*)
\--- io.springfox:springfox-swagger2:3.0.0 (*)

org.slf4j:slf4j-api:1.7.25 -> 1.7.30
+--- ch.qos.logback:logback-classic:1.2.3
| +--- org.liquibase:liquibase-core:3.10.3
| | \--- compileClasspath (requested org.liquibase:liquibase-core)
| \--- org.springframework.boot:spring-boot-starter-logging:2.4.3
| \--- org.springframework.boot:spring-boot-starter:2.4.3
| +--- org.springframework.boot:spring-boot-starter-web:2.4.3
| | \--- compileClasspath (requested org.springframework.boot:spring-boot-starter-web)
| +--- org.springframework.boot:spring-boot-starter-json:2.4.3
| | +--- compileClasspath (requested org.springframework.boot:spring-boot-starter-json)
| | \--- org.springframework.boot:spring-boot-starter-web:2.4.3 (*)
| +--- org.springframework.boot:spring-boot-starter-validation:2.4.3
| | \--- compileClasspath (requested org.springframework.boot:spring-boot-starter-validation)
| +--- org.springframework.boot:spring-boot-starter-security:2.4.3
| | \--- compileClasspath (requested org.springframework.boot:spring-boot-starter-security)
| +--- com.github.pagehelper:pagehelper-spring-boot-starter:1.3.0 (requested org.springframework.boot:spring-boot-starter:2.3.1.RELEASE)
| | \--- compileClasspath
| +--- org.springframework.boot:spring-boot-starter-quartz:2.4.3
| | \--- compileClasspath (requested org.springframework.boot:spring-boot-starter-quartz)
| +--- org.springframework.boot:spring-boot-starter-cache:2.4.3
| | \--- compileClasspath (requested org.springframework.boot:spring-boot-starter-cache)
| +--- org.mybatis.spring.boot:mybatis-spring-boot-starter:2.1.3 (requested org.springframework.boot:spring-boot-starter:2.3.0.RELEASE)
| | \--- com.github.pagehelper:pagehelper-spring-boot-starter:1.3.0 (*)
| +--- org.springframework.boot:spring-boot-starter-jdbc:2.4.3
| | +--- com.baomidou:mybatis-plus-boot-starter:3.4.2 (requested org.springframework.boot:spring-boot-starter-jdbc:2.3.2.RELEASE)
| | | \--- compileClasspath
| | \--- org.mybatis.spring.boot:mybatis-spring-boot-starter:2.1.3 (requested org.springframework.boot:spring-boot-starter-jdbc:2.3.0.RELEASE) (*)
| \--- org.springframework.boot:spring-boot-starter-actuator:2.4.3
| \--- cn.pomit:spring-boot-monitor:0.0.3 (requested org.springframework.boot:spring-boot-starter-actuator:2.0.4.RELEASE)
| \--- compileClasspath
+--- com.alibaba:druid-spring-boot-starter:1.1.16
| \--- compileClasspath
+--- com.jayway.jsonpath:json-path:2.4.0
| \--- us.codecraft:webmagic-core:0.7.5 (requested com.jayway.jsonpath:json-path:2.5.0)
| +--- compileClasspath
| \--- us.codecraft:webmagic-extension:0.7.5
| \--- compileClasspath
+--- com.zaxxer:HikariCP:3.4.5
| \--- org.springframework.boot:spring-boot-starter-jdbc:2.4.3 (*)
+--- io.springfox:springfox-bean-validators:3.0.0
| +--- io.springfox:springfox-boot-starter:3.0.0
| | \--- compileClasspath
| \--- com.github.xiaoymin:knife4j-spring:2.0.9 (requested io.springfox:springfox-bean-validators:2.10.5)
| \--- com.github.xiaoymin:knife4j-spring-boot-autoconfigure:2.0.9
| \--- com.github.xiaoymin:knife4j-spring-boot-starter:2.0.9
| \--- compileClasspath
+--- io.springfox:springfox-boot-starter:3.0.0 (*)
+--- io.springfox:springfox-core:3.0.0
| +--- io.springfox:springfox-oas:3.0.0
| | \--- io.springfox:springfox-boot-starter:3.0.0 (*)
| +--- io.springfox:springfox-data-rest:3.0.0
| | \--- io.springfox:springfox-boot-starter:3.0.0 (*)
| +--- io.springfox:springfox-spring-webmvc:3.0.0
| | +--- io.springfox:springfox-oas:3.0.0 (*)
| | +--- io.springfox:springfox-data-rest:3.0.0 (*)
| | +--- com.github.xiaoymin:knife4j-spring:2.0.9 (requested io.springfox:springfox-spring-webmvc:2.10.5) (*)
| | +--- io.springfox:springfox-swagger2:3.0.0
| | | +--- io.springfox:springfox-boot-starter:3.0.0 (*)
| | | \--- com.github.xiaoymin:knife4j-spring:2.0.9 (requested io.springfox:springfox-swagger2:2.10.5) (*)
| | \--- io.springfox:springfox-swagger-common:3.0.0
| | +--- io.springfox:springfox-oas:3.0.0 (*)
| | \--- io.springfox:springfox-swagger2:3.0.0 (*)
| +--- io.springfox:springfox-spring-web:3.0.0
| | +--- io.springfox:springfox-oas:3.0.0 (*)
| | +--- io.springfox:springfox-bean-validators:3.0.0 (*)
| | +--- io.springfox:springfox-swagger2:3.0.0 (*)
| | +--- io.springfox:springfox-swagger-common:3.0.0 (*)
| | \--- io.springfox:springfox-spring-webmvc:3.0.0 (*)
| +--- io.springfox:springfox-schema:3.0.0
| | +--- io.springfox:springfox-oas:3.0.0 (*)
| | +--- io.springfox:springfox-swagger2:3.0.0 (*)
| | +--- io.springfox:springfox-swagger-common:3.0.0 (*)
| | +--- io.springfox:springfox-spring-webmvc:3.0.0 (*)
| | \--- io.springfox:springfox-spring-web:3.0.0 (*)
| \--- io.springfox:springfox-spi:3.0.0
| +--- io.springfox:springfox-oas:3.0.0 (*)
| +--- io.springfox:springfox-data-rest:3.0.0 (*)
| +--- io.springfox:springfox-swagger2:3.0.0 (*)
| +--- io.springfox:springfox-swagger-common:3.0.0 (*)
| +--- io.springfox:springfox-spring-webmvc:3.0.0 (*)
| +--- io.springfox:springfox-spring-web:3.0.0 (*)
| \--- io.springfox:springfox-schema:3.0.0 (*)
+--- io.springfox:springfox-data-rest:3.0.0 (*)
+--- io.springfox:springfox-oas:3.0.0 (*)
+--- io.springfox:springfox-spring-web:3.0.0 (*)
+--- io.springfox:springfox-spring-webflux:3.0.0
| +--- io.springfox:springfox-oas:3.0.0 (*)
| \--- io.springfox:springfox-swagger2:3.0.0 (*)
+--- io.springfox:springfox-spring-webmvc:3.0.0 (*)
+--- io.springfox:springfox-swagger-common:3.0.0 (*)
+--- io.springfox:springfox-swagger2:3.0.0 (*)
+--- net.sf.ehcache:ehcache:2.10.6
| \--- compileClasspath (requested net.sf.ehcache:ehcache)
+--- org.apache.logging.log4j:log4j-to-slf4j:2.13.3
| \--- org.springframework.boot:spring-boot-starter-logging:2.4.3 (*)
+--- org.springframework.plugin:spring-plugin-core:2.0.0.RELEASE
| +--- io.springfox:springfox-boot-starter:3.0.0 (*)
| +--- io.springfox:springfox-oas:3.0.0 (*)
| +--- io.springfox:springfox-data-rest:3.0.0 (*)
| +--- io.springfox:springfox-bean-validators:3.0.0 (*)
| +--- io.springfox:springfox-swagger2:3.0.0 (*)
| +--- io.springfox:springfox-swagger-common:3.0.0 (*)
| +--- io.springfox:springfox-spring-webmvc:3.0.0 (*)
| +--- io.springfox:springfox-spring-web:3.0.0 (*)
| +--- io.springfox:springfox-core:3.0.0 (*)
| +--- io.springfox:springfox-spring-webflux:3.0.0 (*)
| \--- org.springframework.plugin:spring-plugin-metadata:2.0.0.RELEASE
| +--- io.springfox:springfox-boot-starter:3.0.0 (*)
| +--- io.springfox:springfox-oas:3.0.0 (*)
| +--- io.springfox:springfox-data-rest:3.0.0 (*)
| +--- io.springfox:springfox-bean-validators:3.0.0 (*)
| +--- io.springfox:springfox-swagger2:3.0.0 (*)
| +--- io.springfox:springfox-swagger-common:3.0.0 (*)
| +--- io.springfox:springfox-spring-webmvc:3.0.0 (*)
| +--- io.springfox:springfox-spring-web:3.0.0 (*)
| +--- io.springfox:springfox-core:3.0.0 (*)
| \--- io.springfox:springfox-spring-webflux:3.0.0 (*)
\--- org.springframework.plugin:spring-plugin-metadata:2.0.0.RELEASE (*)

org.slf4j:slf4j-api:1.7.28 -> 1.7.30
+--- com.github.xiaoymin:knife4j-core:2.0.9
| \--- com.github.xiaoymin:knife4j-spring:2.0.9
| \--- com.github.xiaoymin:knife4j-spring-boot-autoconfigure:2.0.9
| \--- com.github.xiaoymin:knife4j-spring-boot-starter:2.0.9
| \--- compileClasspath
\--- org.liquibase:liquibase-core:3.10.3
\--- compileClasspath (requested org.liquibase:liquibase-core)

(*) - dependencies omitted (listed previously)

```
1 change: 1 addition & 0 deletions docs/posts/others/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@
- [Nacos](./014.md)
- [第三方 API 对接推荐的方式(SDK 方式)](./015.md)
- [百分比加权选择](./016.md)
- [Gradle 依赖相关排查](./017.md)

0 comments on commit 72d58c9

Please sign in to comment.