有没有办法排除全局的Maven依赖关系? [英] Is there a way to exclude a Maven dependency globally?

查看:786
本文介绍了有没有办法排除全局的Maven依赖关系?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图找到一种排除传递依赖关系的通用方法,而不必将其从依赖于它的所有依赖项中排除。例如,如果我想排除slf4j,我会执行以下操作:

I’m trying to find a "generic" way of excluding a transitive dependency from being included without having to exclude it from all the dependencies that depend on it. For example, if I want to exclude slf4j, I do the following:

  <dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-jmx</artifactId>
    <version>3.3.2.GA</version>
    <exclusions>
      <exclusion>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
      </exclusion>
    </exclusions>
  </dependency>
  <dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-entitymanager</artifactId>
    <version>3.4.0.GA</version>
    <type>jar</type>
    <exclusions>
      <exclusion>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
      </exclusion>
    </exclusions>
  </dependency>

这部分是为了清理pom文件,部分原因是为了避免将来有人添加依赖关系的问题这取决于排除的依赖关系 - 并忘记排除它。

This is partly to clean up the pom file, partly to avoid issues in the future with people adding dependencies that depend on that excluded dependency — and forgetting to exclude it.

有没有办法?

推荐答案

这是否有帮助? http://jlorenzen.blogspot.com/2009/06/maven-global -excludes.html

假设我想从我的WAR中排除avalon-framework,我会将以下内容添加到我的项目POM中,并提供范围。这适用于所有传递依赖项,并允许您指定一次。

"Assuming I want to exclude avalon-framework from my WAR, I would add the following to my projects POM with a scope of provided. This works across all transitive dependencies and allows you to specify it once.

<dependencies>
  <dependency>
      <artifactId>avalon-framework</artifactId>
      <groupId>avalon-framework</groupId>
      <version>4.1.3</version>
      <scope>provided</scope>
  </dependency>
</dependencies>

即使在父POM中指定它也可以工作,这将阻止项目在所有子POM中声明这一点。

This even works when specifying it in the parent POM, which would prevent projects from having to declare this in all child POMs."

这篇关于有没有办法排除全局的Maven依赖关系?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆