如何简化maven pom中多个依赖项的相同排除

5 eclipse maven

我的 pom 中有几个依赖项会引入不需要的 jar,因此对它们设置了相同的排除:

<dependencies>
  <dependency>
    <groupId>some.group</groupId>
    <artifactId>some-artifact-1</artifactId>
    <version>1</version>
    <exclusions>
      <exclusion>
        <groupId>annoying.group</groupId>
        <artifactId>unwanted-artifact</artifactId>
      </exclusion>
    </exclusions>
  </dependency>
  <dependency>
    <groupId>some.other.group</groupId>
    <artifactId>some-artifact-2</artifactId>
    <version>1</version>
    <exclusions>
      <exclusion>
        <groupId>annoying.group</groupId>
        <artifactId>unwanted-artifact</artifactId>
      </exclusion>
    </exclusions>
  </dependency>
  <dependency>
    <groupId>another.group</groupId>
    <artifactId>some-artifact-3</artifactId>
    <version>1</version>
    <exclusions>
      <exclusion>
        <groupId>annoying.group</groupId>
        <artifactId>unwanted-artifact</artifactId>
      </exclusion>
    </exclusions>
  </dependency>
  .
  .
  .
<dependencies>
Run Code Online (Sandbox Code Playgroud)

问题是我的 poms 有数十个依赖项,因此可能会有更多依赖项拉入不需要的 jar。我不知道如何辨别那些不会带来不必要的依赖的依赖项。

我现在的工作流程是:

  1. 查看我的 pom 并添加对看起来可能需要它的依赖项的排除(从工件和组 ID 判断)。
  2. 确认该 jar 不再位于 Eclipse 中项目的 Maven 依赖项列表中
  3. 添加更多排除项,直到罐子消失(如果还没有)。
  4. 痛苦地检查我给予排除的每个依赖项,然后关闭排除以确认是否确实需要排除。

我的问题是:有更好的方法吗?有没有办法在我的 pom 中设置一般排除,这样我就不必一遍又一遍地重复相同的排除?或者是否有更好的工作流程来排除这个不需要的 jar?

我正在使用 Maven 3.0.4

bma*_*ies 3

遗憾的是,没有办法避免这种情况。“全局”依赖性排除已被讨论但从未实施。