简体   繁体   English

强制maven spring boot项目使用旧版本的依赖项而不是其他依赖项的新版本

[英]Forcing maven spring boot project to use older version of a dependency instead of a new version from another dependency

I'm running in to a problem where I cannot start a spring boot server due to the same problem listed in this question: 由于此问题中列出的问题相同,我遇到了无法启动Spring启动服务器的问题:

How to set up Spring Boot and log4j2 properly? 如何正确设置Spring Boot和log4j2?

I am encountering this scenario because the spring boot project has a dependency on a jar that includes elasticsearch, which includes a new version of slf4j that isn't compatible with spring boot 我遇到这种情况是因为spring boot项目依赖于包含elasticsearch的jar,其中包括与spring boot不兼容的新版本的slf4j

I tried the recommended solution by implementing every exclusion in the elasticsearch project dependency definition possible, but for some reason the new version keeps being picked up. 我通过在elasticsearch项目依赖项定义中实现每个排除项来尝试推荐的解决方案,但由于某种原因,新版本仍然被选中。 I cannot seem to force the spring boot project to ignore the logging packages used by the elasticsearch project. 我似乎无法强制spring boot项目忽略elasticsearch项目使用的日志包。

Here is my pom for the spring-boot project, see the dependency for problematic.project.import : http://pastebin.com/Yeq2qk9Y 这是我的spring-boot项目的pom,请参阅problematic.project.import的依赖项: http//pastebin.com/Yeq2qk9Y

Here is the pom for the project that is being imported into the spring boot project: http://pastebin.com/gknmf6Tt 这是导入春季启动项目的项目的pom: http//pastebin.com/gknmf6Tt

The error I am getting is: 我得到的错误是:

Caused by: java.lang.NoSuchMethodError: org.apache.logging.log4j.core.config.ConfigurationFactory.getConfiguration(Lorg/apache/logging/log4j/core/config/ConfigurationSource;)Lorg/apache/logging/log4j/core/config/Configuration;
at org.springframework.boot.logging.log4j2.Log4J2LoggingSystem.loadConfiguration(Log4J2LoggingSystem.java:165)
at org.springframework.boot.logging.log4j2.Log4J2LoggingSystem.loadDefaults(Log4J2LoggingSystem.java:148)
at org.springframework.boot.logging.AbstractLoggingSystem.initializeWithConventions(AbstractLoggingSystem.java:75)
at org.springframework.boot.logging.AbstractLoggingSystem.initialize(AbstractLoggingSystem.java:50)

Any tips on how to get this issue cleared? 有关如何解决此问题的任何提示已被清除? Is this possible for two versions of this set of libraries to be loaded, each module ignorant to the version they don't need? 这个库的两个版本是否可以加载,每个模块都不知道他们不需要的版本?

You can exclude the cyclic dependencies by using the <exclusions> tag in your pom.xml like this: 您可以使用pom.xml<exclusions>标记排除循环依赖项,如下所示:

<dependency>
  <groupId>sample.ProjectB</groupId>
  <artifactId>Project-B</artifactId>
  <version>1.0-SNAPSHOT</version>
  <exclusions>
    <exclusion>
      <groupId>sample.ProjectE</groupId> <!-- Exclude Project-E from Project-B -->
      <artifactId>Project-E</artifactId>
    </exclusion>
  </exclusions>
</dependency>

You should exclude the cyclic dependency of the newer version from the dependency which is having it and that way only the older version will be loaded and not both. 您应该从具有它的依赖项中排除较新版本的循环依赖性,这样只会加载旧版本而不是两者。

Here is the link for more information: 以下是获取更多信息的链接:

https://maven.apache.org/guides/introduction/introduction-to-optional-and-excludes-dependencies.html https://maven.apache.org/guides/introduction/introduction-to-optional-and-excludes-dependencies.html

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

相关问题 Maven 依赖与较旧的 Spring Boot 版本 - Maven dependency with older spring boot version Java / Maven如何使用使用项目中已使用的另一个依赖项的旧版本的依赖项 - Java/Maven how to use a dependency that uses an older version of another dependency that is already used in the project 行家! Spring Boot 采用了依赖项目中提到的错误依赖版本 - MAVEN! Spring Boot takes wrong dependency version mentioned in dependency project 如何排除旧版本的 maven 依赖并使用它的新版本? - How to exclude older versions of maven dependency and use new version of it? 如何在 Spring Boot 项目的 maven pom.xml 中检查另一个依赖版本? - How to check for another dependency version in the maven pom.xml in a Spring Boot project? 如何从 maven spring 引导项目中所需的 BOM POM 继承依赖版本? - How to inherit dependency version from required BOM POM in maven spring boot project? Maven:将相同工件的旧版本添加为依赖项 - Maven: Add older version of the same artifact as dependency Gradle 项目总是尝试使用旧版本的依赖项 - Gradle Project Always Tries to Use older version of dependency 将 spring boot maven 项目作为依赖添加到另一个项目(本地) - Add spring boot maven project as dependency to another project (locally) 强制Gradle使用早期的依赖版本进行测试 - Forcing Gradle to use an earlier dependency version for testing
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM