从Gradle中的Spring Boot中排除Tomcat依赖项 [英] Excluding Tomcat dependencies from Spring Boot in Gradle
问题描述
build.gradle的相关部分:
compile(org.springframework.boot:spring-boot-starter){
exclude module:tomcat- embed-el
}
compile(org.springframework.boot:spring-boot-starter-jetty)
compile(org.springframework.boot:spring- boot-starter-web){
exclude module:spring-boot-starter-tomcat
}
然而,当我运行 gradle dependencies
部分tomcat仍然存在时,导致WebSockets出现问题:
...
|
+ --- org.springframework.boot:spring-boot-starter-web: - > 1.4.1.RELEASE
| + --- org.springframework.boot:spring-boot-starter:1.4.1.RELEASE(*)
| + --- org.hibernate:hibernate-validator:5.2.4.Final
| | + --- javax.validation:validation-api:1.1.0.Final
| | + --- org.jboss.logging:jboss-logging:3.2.1.Final - > 3.3.0.Final
| | \ --- com.fasterxml:classmate:1.1.0 - > 1.3.1
| + --- com.fasterxml.jackson.core:jackson-databind:2.8.3
| | + --- com.fasterxml.jackson.core:jackson-annotations:2.8.0 - > 2.8.3
| | \ --- com.fasterxml.jackson.core:jackson-core:2.8.3
| + --- org.springframework:spring-web:4.3.3.RELEASE
| | + --- org.springframework:spring-aop:4.3.3.RELEASE(*)
| | + --- org.springframework:spring-beans:4.3.3.RELEASE(*)
| | + --- org.springframework:spring-context:4.3.3.RELEASE(*)
| | \ --- org.springframework:spring-core:4.3.3.RELEASE
| + --- org.springframework:spring-webmvc:4.3.3.RELEASE
| | + --- org.springframework:spring-aop:4.3.3.RELEASE(*)
| | + --- org.springframework:spring-beans:4.3.3.RELEASE(*)
| | + --- org.springframework:spring-context:4.3.3.RELEASE(*)
| | + --- org.springframework:spring-core:4.3.3.RELEASE
| | + --- org.springframework:spring-expression:4.3.3.RELEASE(*)
| | \ --- org.springframework:spring-web:4.3.3.RELEASE(*)
| \ --- org.springframework.boot:spring-boot-starter-tomcat:1.4.1.RELEASE
| + --- org.apache.tomcat.embed:tomcat-embed-core:8.5.5
| + --- org.apache.tomcat.embed:tomcat-embed-el:8.5.5
| \ --- org.apache.tomcat.embed:tomcat-embed-websocket:8.5.5
| \ --- org.apache.tomcat.embed:tomcat-embed-core:8.5.5
...
为什么不是 spring-boot-start-tomcat
不包括 spring-boot-starter-web
?
>我还有 compile(org.springframework.boot:spring-boot-starter-websocket)依赖项也取决于
spring-boot -starter-Tomcat的
。 Gradle依赖关系输出误导我认为 spring-boot-starter-web
是Tomcat仍然存在的原因。
compile(org.springframework.boot:spring-boot-starter-websocket ){
排除模块:spring-boot-starter-tomcat
}
<获得的教训是,当你想排除某些事物时,仔细检查你的所有依赖关系,以确保它被排除在所有地方之外。并且可以改进gradle依赖关系输出以减少误导...
I'm using Spring Boot with Jetty and it seems I cannot exclude all the Tomcat dependencies in my Gradle build file.
Relevant part of build.gradle:
compile("org.springframework.boot:spring-boot-starter") {
exclude module: "tomcat-embed-el"
}
compile("org.springframework.boot:spring-boot-starter-jetty")
compile("org.springframework.boot:spring-boot-starter-web") {
exclude module: "spring-boot-starter-tomcat"
}
Yet when I run gradle dependencies
parts of tomcat are still there, and causing issues with WebSockets:
...
|
+--- org.springframework.boot:spring-boot-starter-web: -> 1.4.1.RELEASE
| +--- org.springframework.boot:spring-boot-starter:1.4.1.RELEASE (*)
| +--- org.hibernate:hibernate-validator:5.2.4.Final
| | +--- javax.validation:validation-api:1.1.0.Final
| | +--- org.jboss.logging:jboss-logging:3.2.1.Final -> 3.3.0.Final
| | \--- com.fasterxml:classmate:1.1.0 -> 1.3.1
| +--- com.fasterxml.jackson.core:jackson-databind:2.8.3
| | +--- com.fasterxml.jackson.core:jackson-annotations:2.8.0 -> 2.8.3
| | \--- com.fasterxml.jackson.core:jackson-core:2.8.3
| +--- org.springframework:spring-web:4.3.3.RELEASE
| | +--- org.springframework:spring-aop:4.3.3.RELEASE (*)
| | +--- org.springframework:spring-beans:4.3.3.RELEASE (*)
| | +--- org.springframework:spring-context:4.3.3.RELEASE (*)
| | \--- org.springframework:spring-core:4.3.3.RELEASE
| +--- org.springframework:spring-webmvc:4.3.3.RELEASE
| | +--- org.springframework:spring-aop:4.3.3.RELEASE (*)
| | +--- org.springframework:spring-beans:4.3.3.RELEASE (*)
| | +--- org.springframework:spring-context:4.3.3.RELEASE (*)
| | +--- org.springframework:spring-core:4.3.3.RELEASE
| | +--- org.springframework:spring-expression:4.3.3.RELEASE (*)
| | \--- org.springframework:spring-web:4.3.3.RELEASE (*)
| \--- org.springframework.boot:spring-boot-starter-tomcat:1.4.1.RELEASE
| +--- org.apache.tomcat.embed:tomcat-embed-core:8.5.5
| +--- org.apache.tomcat.embed:tomcat-embed-el:8.5.5
| \--- org.apache.tomcat.embed:tomcat-embed-websocket:8.5.5
| \--- org.apache.tomcat.embed:tomcat-embed-core:8.5.5
...
Why isn't spring-boot-starter-tomcat
excluded from spring-boot-starter-web
?
Aha, found the reason.
I also had compile("org.springframework.boot:spring-boot-starter-websocket")
dependency that was also depending on spring-boot-starter-tomcat
. Gradle dependency output mislead me into thinking that spring-boot-starter-web
is the reason why Tomcat was still there.
I had to add the following:
compile("org.springframework.boot:spring-boot-starter-websocket") {
exclude module: "spring-boot-starter-tomcat"
}
Lesson learned is that when you want to exclude something, double-check all of your dependencies to make sure it is excluded from all the places. And gradle dependencies output could be improved to make it less misleading...
这篇关于从Gradle中的Spring Boot中排除Tomcat依赖项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!