# Gradle 依赖相关排查

# 依赖树 dependencies

该知识在 官方文档 - 查看和调试依赖关系 (opens new window) 中有说到

# 打印依赖树
./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)
# 上面也告诉了,括号里面的 * 之类的是什么含义

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
  • (c):依赖约束(dependency constraint(这个知识我还没学会))
  • (*):省略的依赖项(之前已列出)
  • (n) :未解析(配置不需要解析)

# 依赖洞察 dependencyInsight

该知识在 官方文档 - 查看和调试依赖关系 (opens new window) 中有说到

最简单的使用方式使用 --dependency <dependency> 指令,比如说,在依赖树中看到这样一个信息:

# 
+--- net.sf.ehcache:ehcache -> 2.10.6
|    \--- org.slf4j:slf4j-api:1.7.25 -> 1.7.30
1
2
3

slf4j-api1.7.25 的版本,最后使用了 1.7.30 的版本,这是怎么回事?

# 语法
./gradlew dependencyInsight --dependency <dependency group:name 方式,或者其中一个>
1
2

在这里我们使用以下命令查看

./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
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200