简体   繁体   English

删除maven中的传递依赖项

[英]removing a transitive dependency in maven

I am working on porting some legacy code to a new versions . 我正在努力将一些遗留代码移植到新版本。 one particular module (slf4j) in which 1.5x versions are incompatible with 1.6x and 1.7x , my problem is a project that my project depends on is included as an jar in the classpath . 一个特定的模块(slf4j),其中1.5x版本与1.6x和1.7x不兼容,我的问题是我的项目依赖的项目作为jar路径包含在类路径中。 Is there a way to get around such a problem ? 有办法解决这个问题吗?

If there is a direct dependency in pom Maven will use it and omit any transitive dependencies to the same artifact, eg here 如果pom中存在直接依赖关系,Maven将使用它并省略对同一工件的任何传递依赖性,例如此处

<dependency>
    <groupId>org.apache.camel</groupId>
    <artifactId>camel-core</artifactId>
    <version>2.12.1</version>
</dependency>
<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-api</artifactId>
    <version>1.7.5</version>
</dependency>

camel-core has a transitive dependency slf4j-api-1.6.6 but Maven will choose slf4j-api-1.7.5 camel-core有一个传递依赖slf4j-api-1.6.6但Maven会选择slf4j-api-1.7.5

The way I solved my issue is to redeploy the project that my project depended on . 我解决问题的方法是重新部署我的项目所依赖的项目。 Since it was a jar I had to recreate it in a maven format and add the necessary exclusion statements to stop all transitive dependencies at that level . 因为它是一个jar我必须以maven格式重新创建它并添加必要的排除语句来停止该级别的所有传递依赖。 This may not be best practice but worked in my case . 这可能不是最好的做法,但在我的情况下工作。 I guess with the newer version of projects being all maven based exclude tags should be enough 我想更新版本的项目都是基于maven的排除标签应该足够了

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

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