Gradle의 Spring Boot에서 Tomcat 종속성 제외
저는 Jetty와 함께 Spring Boot을 사용하고 있는데, 제 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 dependenciesTomcat의 일부는 여전히 존재하며 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?
아하, 이유를 찾았습니다.
저도 있었습니다.compile("org.springframework.boot:spring-boot-starter-websocket")의존성 또한 의존적이었습니다.spring-boot-starter-tomcatGradle 의존성 출력은 저를 오해하게 합니다.spring-boot-starter-web톰캣이 아직 거기 있었던 이유입니다.
다음 사항을 추가해야 했습니다.
compile("org.springframework.boot:spring-boot-starter-websocket") {
exclude module: "spring-boot-starter-tomcat"
}
어떤 것을 제외하고 싶을 때 모든 종속성을 다시 확인하여 모든 위치에서 제외되도록 해야 한다는 교훈을 얻을 수 있습니다.그리고 Gradle 의존성 출력을 개선하여 오해를 덜 유발할 수 있습니다.
저도 같은 문제가 있어서 스프링부트-스타트-톰캣을 제외하는 것 외에 톰캣-임베디드-* 병도 제외해야 했습니다. 그라들 구성을 통해 이 작업을 수행했습니다.
configurations {
compile.exclude module: 'spring-boot-starter-tomcat'
compile.exclude group: 'org.apache.tomcat'
}
Kotlin DSL 사용, 추가build.gradle.kts:
configurations {
implementation.configure {
exclude(module = "spring-boot-starter-tomcat")
exclude("org.apache.tomcat")
}
}
으스스
Gradle 6에서는 위에서 언급한 모듈 제외 없이도 이 작업이 가능했습니다.
configurations {
compile.exclude module: 'spring-boot-starter-tomcat'
}
플러그인 구성
스프링 부트 그래들 플러그인 설명서 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
크레시미르 네스크의 답변은 제가 버그를 해결하도록 영감을 주었습니다.하지만 저는 조금 다른 방법으로 해결합니다.
제 문제는 Kotlin의 WebFlux 및 springCoroutines에 구축된 모듈의 Spring-Boot이 포함된 다른 모듈을 포함함으로써 발생합니다.
코틀린에서 제가 가는 길은:
exclude("org.springframework.boot", "spring-boot-starter-tomcat")
첫 번째 주장"org.springframework.boot"그룹용이고, 두 번째는 특정 모듈용입니다.
종속성의 전체 예(Kotlin DSL):
implementation(group = "org.springframework.boot", name = "spring-boot-starter-web") {
exclude(module = "spring-boot-starter-tomcat")
}
Gradle 7.5.1
이를 build.gradle에 추가하기만 하면 되었습니다.
configurations.all {
exclude group: "org.springframework.boot", module: "spring-boot-starter-tomcat"
exclude group: "org.apache.tomcat.embed", module: "tomcat-embed-el"
}
사용할 필요 없음exclude프로젝트 종속성의 절입니다.(IntelliJ를 사용하는 경우 그라들 변경 사항을 로드/재로드하는 것을 잊지 마십시오.)
언급URL : https://stackoverflow.com/questions/42275516/excluding-tomcat-dependencies-from-spring-boot-in-gradle
'programing' 카테고리의 다른 글
| 판다: 모든 NaN과 함께 열을 내립니다. (0) | 2023.07.21 |
|---|---|
| 두 날짜 사이의 월을 찾는 가장 좋은 방법 (0) | 2023.07.21 |
| numpy 배열에서 모드를 찾는 가장 효율적인 방법 (0) | 2023.07.21 |
| ResponseEntity에서 CREATED 상태(201 HTTP)를 반환하는 방법 (0) | 2023.07.21 |
| 이벤트 기반 설계와 도메인 기반 설계 마이크로서비스의 차이점은 무엇입니까? (0) | 2023.07.21 |