Maven 程序集插件 - 如何生成具有自定义文件扩展名的工件?

Maven assembly plug-in - how to produce artifact with custom file extension?

我正在从以下...

中生成一个名为 foo.bar.zip 的工件

我的 pom.xml 插件条目如下所示:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-assembly-plugin</artifactId>
    <configuration>
        <descriptor>src/assembly/bin.xml</descriptor>
        <finalName>foo.bar</finalName>
    </configuration>
    <executions>
        <execution>
            <phase>package</phase>
                <goals>
                    <goal>single</goal>
                </goals>
        </execution>
    </executions>
</plugin> 

我的描述符文件如下所示:

<?xml version="1.0" encoding="UTF-8"?>
<assembly>
<formats>
    <format>zip</format>
</formats>
<fileSets>

etc. etc. 

我的问题是,如何生成具有自定义扩展名的文件?例如。使用名称 foo.bar 而不是 foo.bar.zip

Assembly 仅支持这些格式:

"zip" - Creates a ZIP file format

"tar" - Creates a TAR format

"tar.gz" or "tgz" - Creates a gzip'd TAR format

"tar.bz2" or "tbz2" - Creates a bzip'd TAR format

"jar" - Creates a JAR format

"dir" - Creates an exploded directory format

"war" - Creates a WAR format

您应该考虑在以后 goal/phase 中使用 antrun plugin 重命名文件扩展名

我通过结合解决了这个问题:

  1. maven-assembly-plugin
  2. copy-rename-maven-plugin
  3. build-helper-maven-plugin

程序集插件有一个不附加文件的配置选项,所以我这样做了:

<configuration>
    ...
    <attach>false</attach>
</configuration>

然后我使用 copy-rename-maven-pluginassembly-plugin 生成的文件从 zip 重命名为我的自定义文件类型(在我的例子中是 CLI)。

之后,我使用 build-helper-maven-plugin 将工件附加到自定义文件类型。