【发布时间】:2022-08-16 09:15:50
【问题描述】:
我有一个 spring-boot gradle 项目。它具有依赖关系的依赖关系,我由于内部原因无法使用。我已经分叉了该模块并将其发布到我的存储库中,并带有我想在我的项目中使用的自己的版本号。
部分依赖树如下所示:
compileClasspath - Compile classpath for source set \'main\'.
+--- org.springframework.boot:spring-boot-starter-web:2.7.2
| +--- org.springframework.boot:spring-boot-starter-tomcat:2.7.2
| | +--- jakarta.annotation:jakarta.annotation-api:1.3.5
| | +--- org.apache.tomcat.embed:tomcat-embed-core:9.0.65
| | +--- org.apache.tomcat.embed:tomcat-embed-el:9.0.65
| | \\--- org.apache.tomcat.embed:tomcat-embed-websocket:9.0.65
我需要强制我的项目使用底部两个模块的自定义版本,让我们将新版本称为org.apache.tomcat.embed:tomcat-embed-el:9.0.65.CUSTOM 和org.apache.tomcat.embed:tomcat-embed-websocket:9.0.65.CUSTOM。
我从来没有尝试过这个。我正在我的项目的 build.gradle 文件中尝试所有不同的设置,例如
configurations { main }
configurations.main.resolutionStrategy.dependencySubstitution {
substitute module(\'org.apache.tomcat.embed:tomcat-embed-el:9.0.65\') using module(\'org.apache.tomcat.embed:tomcat-embed-el:9.0.65.CUSTOM\')
substitute module(\'org.apache.tomcat.embed:tomcat-embed-websocket:9.0.65\') using module(\'org.apache.tomcat.embed:tomcat-embed-websocket:9.0.65.CUSTOM\')
}
但是 9.0.65 版本不断被注入。所以我的问题是:
- 我是否错误地使用了dependencySubstitution,它应该在build.gradle 的什么位置?
- dependencySubstitution 是否适用于依赖项的依赖项(令人作呕),还是仅适用于直接依赖项?
- 没有分叉所有这些依赖项来声明它们的依赖项,有什么方法可以强制我的 Gradle绝不使用版本
9.0.65和只要曾经使用过9.0.65.CUSTOM,无论它在依赖树中的位置如何?
-
也许`configurations.main.resolutionStrategy { force \'org.apache.tomcat.embed:tomcat-embed-el:9.0.65.CUSTOM\' force \'org.apache.tomcat.embed:tomcat-embed-websocket:9.0 .65.CUSTOM\' } ` 如果没记错的话。
-
那不编译。显示错误:\“在 org.gradle.api.internal.artifacts 类型的对象上找不到参数 [org.apache.tomcat.embed:tomcat-embed-el:9.0.65.CUSTOM] 的方法 force()。 ivyservice.dependencysubstitution.DefaultDependencySubstitutions.\"。顺便说一句,我正在使用 Gradle 版本 6.8.1。
-
我不会称之为“依赖注入”,也不会这样标记它。请参阅en.wikipedia.org/wiki/Dependency_injection 了解该术语的普遍理解。
-
该手册有一个配方,我没有尝试过,但它可能只是工作:docs.gradle.org/6.8.1/userguide/…
-
我认为最大的障碍是您创建自己的配置(“main”),并让替换只适用于那里。
configurations.all将包含所有有趣的配置。
标签: spring spring-boot gradle