使用 Maven 程序集插件从带有依赖项的 jar 中删除文件



我使用 maven-assembly-plugin 版本 3.1.1 来制作一个包含所有依赖项的 jar。 我想排除我的应用程序.yml,但是我无法将其从jar中删除。

绒球.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>

此外,我的文件集中的排除也无用。

也在文件集和依赖集中尝试了这种模式,但 application.yml 仍然包括:

<exclude>
**/application.yml
</exclude>

有效的解决方案,我忘了在汇编文件中添加解包选项:

绒球.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>

最新更新