我正在使用Spring Boot和Jetty,似乎我无法排除Gradle构建文件中的所有Tomcat依赖项。
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-starter-tomcat
不排除spring-boot-starter-web
?
答案 0 :(得分:15)
我也有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") {
exclude module: "spring-boot-starter-tomcat"
}
经验教训是,当您想要排除某些内容时,请仔细检查所有依赖项,以确保将其排除在所有位置之外。并且可以改进gradle依赖项输出以减少误导......
答案 1 :(得分:12)
我遇到了同样的问题,所以除了 spring-boot-starter-tomcat 之外我还必须排除 tomcat-embed - * jars,我这样做了通过 gradle配置
configurations {
compile.exclude module: 'spring-boot-starter-tomcat'
compile.exclude group: 'org.apache.tomcat'
}
答案 2 :(得分:1)
有了Gradle 6,这对我有用,而没有上面提到的模块排除:
configurations {
compile.exclude module: 'spring-boot-starter-tomcat'
}
spring boot gradle plugin documentation 4.2.1建议声明这样提供的依赖项(假设您发动了战争):
providedRuntime 'org.springframework.boot:spring-boot-starter-tomcat'
依赖关系不会从战争中删除,而是会转移到通常不会造成伤害的位置。
WEB-INF/lib-provided/spring-boot-starter-tomcat-2.2.4.RELEASE.jar
WEB-INF/lib-provided/tomcat-embed-websocket-9.0.30.jar
WEB-INF/lib-provided/tomcat-embed-core-9.0.30.jar
WEB-INF/lib-provided/tomcat-embed-el-9.0.30.jar
答案 3 :(得分:1)
使用 kotlin gradle dsl:
configurations {
implementation.configure {
exclude(module = "spring-boot-starter-tomcat")
exclude("org.apache.tomcat")
}
}