覆盖 maven-assembly-plugin 输出文件名

Override maven-assembly-plugin output file name

是否可以覆盖 运行 创建的 jar 文件的默认名称以达到 assembly:single 目标?我想添加一个具有非标准名称的依赖项的 jar。我正在使用插件的 2.6 版。

是的,您需要使用 finalName configuration attribute. Note that you probaby also want to remove the assembly id that is appended by default to the final name, with the help of the appendAssemblyId 属性。

示例配置:

<plugin>
  <artifactId>maven-assembly-plugin</artifactId>
  <version>2.6</version>
  <configuration>
    ...
    <finalName>myFinalName</finalName>
    <appendAssemblyId>false</appendAssemblyId>
  </configuration>
</plugin>

执行此操作的正确方法(如 on Maven JIRA tracker 所述)是设置 build.finalName 而不是使用只读 finalName 插件 属性。这是一个如何摆脱“jar-with-dependencies”和版本的例子,这对于创建一个稳定的名称和消除 2 个 JAR 的潜在混淆存在以用于 README 指令非常有用:

  <build>
    <finalName>${project.artifactId}</finalName>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-assembly-plugin</artifactId>
        <version>3.3.0</version>
        <executions>
          <execution>
...
            <configuration>
              <appendAssemblyId>false</appendAssemblyId>
...
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
</build>