从 Maven 依赖项中排除文件

问题描述 投票:0回答:1

我有一个正常的 Maven 依赖

<dependency>
    <groupId>a.b.c.com</groupId>
    <artifactId>xyz</artifactId>
    <classifier>dist</classifier>
    <version>1.234</version>
    <type>zip</type>
</dependency>

这不是一个罐子。它只是一组 .q 文件(q 语言)。 我想排除某些文件。

我尝试了一些方法,但似乎没有任何效果。

在构建中,我添加了一个 maven-dependency-plugin,其中 unpack-dependency 作为 id,phase 作为包,解包目标,并且在配置内部,具有正确的 groupId、artifactId、version、classifier、type 和排除。

  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-dependency-plugin</artifactId>
    <version>3.6.0</version>
    <executions>
      <execution>
        <id>unpack-dependencies</id>
        <phase>package</phase>
        <goals>
            <goal>unpack</goal>
        </goals>
        <configuration>
            <artifactItems>
                <artifactItem>
              <groupId>a.b.c.com</groupId>
              <artifactId>xyz</artifactId>
              <version>1.1234</version>
              <type>zip</type>
              <classifier>dist</classifier>
              <excludes>code/lib/libcommon/filetoexclude.q</excludes>
            </artifactItem>
          </artifactItems> 
        </configuration>
     </execution>
    </executions>
 </plugin>

我可以在日志记录中看到它被记录为已排除,但当我查看实际的目标文件夹时,它仍然在那里。

我错过了什么?

maven dependencies kdb
1个回答
0
投票

正如每个文档

dependency:unpack-dependencies
只是“将项目依赖项从存储库解压到定义的位置”,那么您就可以对解压的资源执行某些操作。

我在应用程序中也有类似的场景:依赖项包含 .drl 文件(Drools 语言)的集合,并且我的应用程序必须仅使用这些文件的子集。我没有以物理方式删除不需要的文件,而是保持依赖关系不变(恕我直言,它应该是这样),并且使用名为“rulesPath”的配置参数来列出应用程序使用的文件。任何其他 .drl 文件都会被忽略。换句话说,我在运行时(在我的应用程序中)解决问题,而不是在构建时(在 Maven 中)。

© www.soinside.com 2019 - 2024. All rights reserved.