maven 添加 zip 文件以部署到远程服务器

Art*_*iev 1 java zip maven-3 maven maven-deploy-plugin

我有 Maven 项目。当我在文件夹中单击安装maven 构建zipjar文件时target

但是当我单击部署时,它只会将jar文件和依赖项部署到远程存储库。

问题:如何使用标准 maven 插件添加 zip 文件以部署到远程 nexus 存储库。

编辑

<packaging>custom-zip<packaging>

A_D*_*teo 5

为了正确地installdeploy额外的工件(由构建生成的文件,通常也遵循其版本控制和相关项目结果的连贯部分),您需要附加到构建中,以便 Maven 将其作为官方交付处理其结果。

要将文件附加到构建,您可以使用build-helper-maven-plugin.

以下是其使用页面的示例片段:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>build-helper-maven-plugin</artifactId>
    <version>1.12</version>
    <executions>
      <execution>
        <id>attach-artifacts</id>
        <phase>package</phase>
        <goals>
          <goal>attach-artifact</goal>
        </goals>
        <configuration>
          <artifacts>
            <artifact>
              <file>the-generated-file</file>
              <type>extension of your file</type>
              <classifier>optional</classifier>
            </artifact>
          </artifacts>
        </configuration>
      </execution>
    </executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)

您应该将上面的配置放在负责生成文件的插件声明之后,也就是说,当您尝试将其附加到构建时,该文件应该存在。查看file配置元素,在这里您应该指定文件,例如target\myfile.zip. 在这种情况下,它将在package阶段期间附加,以便installdeploy阶段在处理过程中将其考虑在内。

调用时

mvn clean install
Run Code Online (Sandbox Code Playgroud)

然后,您将看到构建输出的一部分:

[INFO] --- build-helper-maven-plugin:1.12:attach-artifact (attach-artifacts) @ zip-example ---
[INFO]
[INFO] --- maven-install-plugin:2.4:install (default-install) @ zip-example ---
[INFO] Installing C:\data\eclipse-workspace\zip-example\target\zip-example-0.0.1-SNAPSHOT.jar to c:\data\m2\repository\com\sample\zip-example\0.0.1-SNAPSHOT\zip-example-0.0.1-SNAPSHOT.jar
[INFO] Installing C:\data\eclipse-workspace\zip-example\pom.xml to c:\data\m2\repository\com\sample\zip-example\0.0.1-SNAPSHOT\zip-example-0.0.1-SNAPSHOT.pom
[INFO] Installing C:\data\eclipse-workspace\zip-example\sample.zip to c:\data\m2\repository\com\sample\zip-example\0.0.1-SNAPSHOT\zip-example-0.0.1-SNAPSHOT-optional.zip
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
Run Code Online (Sandbox Code Playgroud)

注意:sample.zip实际上是m2作为复制到本地存储库的zip-example-0.0.1-SNAPSHOT-optional.zip,因此根据项目配置(artifactIdversionclassifier)重命名。