maven - 使用 maven 程序集插件从 jar-with-dependencies 中删除文件
问题描述
我使用 maven-assembly-plugin 3.1.1 版来制作一个包含所有依赖项的 jar。我想排除我的 application.yml 但是我无法从 jar 中删除它。
pom.xml:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.1.1</version>
<configuration>
<descriptors>
<descriptor>env/assembly/descriptor.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
我的描述符.xml:
<assembly xmlns="http://maven.apache.org/ASSEMBLY/2.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.1.0 http://maven.apache.org/xsd/assembly-2.1.0.xsd">
<id>test</id>
<formats>
<format>jar</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<dependencySets>
<dependencySet>
<outputDirectory>/</outputDirectory>
<useProjectArtifact>true</useProjectArtifact>
<unpack>true</unpack>
<scope>compile</scope>
<excludes>
<exclude>
application.yml
</exclude>
</excludes>
</dependencySet>
</dependencySets>
<fileSets>
<fileSet>
<outputDirectory>/</outputDirectory>
<directory>${project.build.outputDirectory}</directory>
<excludes>
<exclude>
application.yml
</exclude>
</excludes>
</fileSet>
</fileSets>
</assembly>
结果 :
The following patterns were never triggered in this artifact exclusion filter:
o 'application.yml'
如果我使用 * 模式而不是 application.yml,则所有文件都将被很好地删除。
我试图放置绝对路径,但它没有任何改变:
<excludes>
<exclude>
env/dev/conf/application.yml
</exclude>
</excludes>
我的 fileSets 接缝中的排除也无用。
还在 fileSets 和 dependencySet 中尝试了这种模式,但 application.yml 仍然包括:
<exclude>
**/application.yml
</exclude>
解决方案
有效的解决方案,我忘了在程序集文件中添加 unpackOptions :
pom.xml:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.1.1</version>
<executions>
<execution>
<id>make-jar</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptors>
<descriptor>env/assembly/descriptor.xml</descriptor>
</descriptors>
</configuration>
</execution>
</executions>
</plugin>
描述符.xml:
<assembly xmlns="http://maven.apache.org/ASSEMBLY/2.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.1.0 http://maven.apache.org/xsd/assembly-2.1.0.xsd">
<id>jar-with-dependencies</id>
<formats>
<format>jar</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<fileSets>
<fileSet>
<outputDirectory>/</outputDirectory>
<directory>${project.basedir}</directory>
</fileSet>
</fileSets>
<dependencySets>
<dependencySet>
<outputDirectory>/</outputDirectory>
<useProjectArtifact>true</useProjectArtifact>
<unpack>true</unpack>
<scope>runtime</scope>
<unpackOptions>
<excludes>
<exclude>**/application.yml</exclude>
</excludes>
</unpackOptions>
</dependencySet>
</dependencySets>
</assembly>
推荐阅读
- mysql - 每个组的第一行按顺序排列
- python-3.x - 堆积条显示 Matplotlib 中 2 个变量的百分比值?
- ruby-on-rails - Mongoid Search Gem 不会更新关联关键字
- c++ - 无论如何我可以在结构中声明一个二维数组并将其传递给函数以在 C++ 中输入数字吗?
- amazon-web-services - 将文件功能与 Terraform 工作区一起使用
- javascript - 如何删除所有数据并更新页面而不使用 useEffect 刷新
- node.js - 为 MongoDB 3.6 的 Azure Cosmos DB API 使用 insertMany 时出错
- java - Java 解析不同的 JSON 响应和节点
- java - AnyLogic 如何创建自己的类并从行人模型中调用它们?
- powershell - RubberDucky键盘记录器