有没有办法在全局范围内排除 Maven 依赖项? [英] Is there a way to exclude a Maven dependency globally?

查看:48
本文介绍了有没有办法在全局范围内排除 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天全站免登陆