如何从Maven依赖中排除一些JAR包内的包?

3

我在我的Maven项目中依赖一个库,但是发现该库的JAR包含一些导致应用程序失败的包。我相信如果我能通过某种方式排除这些包,该库仍然可以工作,但我想通过Maven而不是自己修改JAR文件来完成这个操作。是否有一种方法可以使用Maven来排除这些包?

1个回答

4

您可以查看 maven-shade-plugin 插件。官方文档中提供了一个示例,链接为 docs

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-shade-plugin</artifactId>
    <version>2.3</version>
    <executions>
      <execution>
        <phase>package</phase>
        <goals>
          <goal>shade</goal>
        </goals>
        <configuration>
          <filters>
            <filter>
              <artifact>junit:junit</artifact>
              <includes>
                <include>junit/framework/**</include>
                <include>org/junit/**</include>
              </includes>
              <excludes>
                <exclude>org/junit/experimental/**</exclude>
                <exclude>org/junit/runners/**</exclude>
              </excludes>
            </filter>
            <filter>
              <artifact>*:*</artifact>
              <excludes>
                <exclude>META-INF/*.SF</exclude>
                <exclude>META-INF/*.DSA</exclude>
                <exclude>META-INF/*.RSA</exclude>
              </excludes>
            </filter>
          </filters>
        </configuration>
      </execution>
    </executions>
  </plugin>

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接