程序集未排除pom.xml中的Maven依赖项排除 [英] Maven dependency exclusions in pom.xml are not excluded by assembly

查看:144
本文介绍了程序集未排除pom.xml中的Maven依赖项排除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我有一个项目,其中从我的一个依赖项中排除了所有传递性依赖项(oracle jdbc顽固地提取了可能需要的所有jar,这给我带来了问题通过替换我的xml解析器).

So I have a project in which I've excluded all of the transitive dependencies from one of my dependencies (oracle jdbc stubbornly pulls in all of the jars someone might need, which causes issues for me by replacing my xml parser).

我的项目的程序集使用dependencySet提取我需要的jar,但这根本不考虑这些排除:应该排除的jar显示在最终包中.

My project's assembly uses a dependencySet to pull in the jars that I need, but this doesn't respect these exclusions at all: the jars that should be excluded are showing up in the final package.

我知道我可以在程序集描述符本身中明确排除这些依赖关系,但是不希望在两个地方都维护排除项,如果在pom.xml中有很多排除项,这将变得很笨拙

I know that I can explicitly exclude these dependencies in the assembly descriptor itself but its undesirable to have to maintain exclusions in two places and this grows unwieldy if you have lots of exclusions in the pom.xml

最小复制示例:

$ find
.
./src
./src/assembly
./src/assembly/tar.gz.xml
./pom.xml

pom.xml

<?xml version="1.0"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>bug.maven</groupId>
  <artifactId>maven-bug</artifactId>
  <version>1-SNAPSHOT</version>
  <packaging>jar</packaging>
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-assembly-plugin</artifactId>
        <version>2.6</version>
        <configuration>
          <descriptors>
            <descriptor>src/assembly/tar.gz.xml</descriptor>
          </descriptors>
          <finalName>maven-bug-${project.version}</finalName>
        </configuration>
        <executions>
          <execution>
            <phase>package</phase>
            <goals>
              <goal>attached</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
  <dependencies>
    <dependency>
      <groupId>commons-validator</groupId>
      <artifactId>commons-validator</artifactId>
      <version>1.4.1</version>
      <exclusions>
        <exclusion>
          <groupId>*</groupId>
          <artifactId>*</artifactId>
        </exclusion>
      </exclusions>
    </dependency>
  </dependencies>
</project>

src/assembly/tar.gz.xml

<?xml version="1.0"?>
<assembly>
  <id>pkg</id>
  <formats>
    <format>tar.gz</format>
  </formats>
  <includeBaseDirectory>false</includeBaseDirectory>
  <dependencySets>
    <dependencySet>
      <outputDirectory>/lib</outputDirectory>
      <useProjectArtifact>false</useProjectArtifact>
    </dependencySet>
  </dependencySets>
</assembly>

要复制

$ mvn clean package
$ tar tzf target/maven-bug-1-SNAPSHOT-pkg.tar.gz
lib/commons-validator-1.4.1.jar
lib/commons-beanutils-1.8.3.jar
lib/commons-logging-1.2.jar
lib/commons-digester-1.8.1.jar
lib/commons-collections-3.2.1.jar

预期结果

$ mvn clean package
$ tar tzf target/maven-bug-1-SNAPSHOT-pkg.tar.gz
lib/commons-validator-1.4.1.jar

据我所知,这只是没有在Maven中编写文档的错误.有人有我想念的想法或解决方案吗?

From what I can tell this is just a bug without documentation in maven. Does anyone have an idea that I'm missing or solution?

推荐答案

编辑

版本3.1.1

Edit

Version 3.1.1 of the maven-assembly-plugin has been released Jan 01, 2019 and now honors wildcards in dependencies exclusions. Simply upgrade the plugin.

就像我在此答案中解释的那样,Maven程序集插件(version <= 3.1.0)在依赖项排除中不支持通配符.

Like I explained in this answer, Maven assembly plugin (version <= 3.1.0) did not honor wildcards in dependencies exclusions.

此提交对其进行了修复,但已发布插件(版本3.1.1)在撰写本文时尚未制作.

This commit fixes it, but the release of the plugin (version 3.1.1) has not been made yet at the moment of writing.

到目前为止(version <= 3.1.0),最干净的解决方案是显式声明所有排除的依赖项,而不使用通配符.

As of now (version <= 3.1.0), the cleanest solution is to explicitly declare all excluded dependencies, without wildcards.

这篇关于程序集未排除pom.xml中的Maven依赖项排除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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