简体   繁体   English

Maven强制依赖项使用较低版本的Spring Boot

[英]Maven force Dependencies to use Spring Boot lower version

My Spring Boot application's spring boot parent version is 1.5. 我的Spring Boot应用程序的spring boot父版本是1.5。 There is a custom dependency whose spring boot version is 2.0. 有一个自定义依赖项,其春季启动版本为2.0。 I want to force this dependency to use spring boot 1.5 in main Spring Boot application. 我想强制这种依赖性在主Spring Boot应用程序中使用spring boot 1.5。
Given that: Dependency's version cannot be downgraded as it is being used by other apps and cannot upgrade the spring boot main app to 2.0 from 1.5. 鉴于此:依赖关系的版本无法降级,因为它正在被其他应用程序使用,并且无法将Spring Boot主应用程序从1.5升级到2.0。 Dependency works well for both SB 1.5 and 2.0 well. SB 1.5和2.0的依赖性都很好。 Exclusion tags were also added to exclude springboot 1.5. 还添加了排除标签以排除springboot 1.5。 but it was also not successful. 但是也没有成功。

Please let me know how to force the dependency to use 1.5 at run time ? 请让我知道如何在运行时强制依赖项使用1.5?

You cannot change the parent POM of a dependency. 您不能更改依赖项的父POM。

You can, though, overwrite dependencies that are defined in a dependency's parent POM. 但是,您可以覆盖在依赖项的父POM中定义的依赖项。 This can be done using the same mechanisms as overwriting other transitive dependencies ( <dependencyManagement> ). 可以使用与覆盖其他可传递依赖项( <dependencyManagement> )相同的机制来完成此操作。

As dependencies are the only way a parent POM of a dependency contributes to your build, you have no need to change it. 由于依赖关系是依赖关系的父POM参与构建的唯一方法,因此您无需更改它。

You can enforce consistent dependencies in whole project with rule Dependency Convergence. 您可以使用规则Dependency Convergence在整个项目中实施一致的依赖关系。

<plugin>
     <groupId>org.apache.maven.plugins</groupId>
     <artifactId>maven-enforcer-plugin</artifactId>
     <version>1.3.1</version>
     <executions>
        <execution>
           <id>enforce</id>
           <configuration>
              <rules>
                 <DependencyConvergence/>
              </rules>
           </configuration>
           <goals>
              <goal>enforce</goal>
           </goals>
        </execution>
     </executions>
  </plugin>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM