1
votes

I have maven project. When I click install maven build zip and jar file in target folder.

But when i click deploy it only deploy jar file and dependencies to remote repository.

Question: How I can add zip file to deploy to remote nexus repository with standard maven plugins.

EDIT

<packaging>custom-zip<packaging>

1
the .zip file is part of the target folder content, but is it copied to the local m2 cache? I presume not, only the .jar should be there, consistently with the deploy behavior then. Can you share more of the concerned pom.xml file? Most probably the zip file is generated by not attached to the build as additional artifact - A_Di-Matteo
@A_Di-Matteo yes, you right. Only .jar in local m2 cache. I just have special plugin custom-plugin-packaging-zip And this plugin make for me zip file in target folder. How I can attach this to build as additional artifact? - Artur Ganiev

1 Answers

5
votes

In order to properly install and deploy an additional artifact (a file generated by the build, normally also following its versioning and coherently part of the outcome of the concerned project), you need to attach it to the build so that Maven will handle it as official deliverable of its outcome.

To attach a file to the build, you can use the build-helper-maven-plugin.

Here is a sample snippet from its usage page:

<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>

You should place the configuration above after the plugin declaration which is responsible for the generation of the file, that is, the file should exist when you try to attach it to the build. Look at the file configuration element, here you should specify the file, e.g. target\myfile.zip. In this case it will be attached during the package phase so that the install and deploy phase would take it into account during their processing.

When invoking

mvn clean install

You would then see as part of the build output:

[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] ------------------------------------------------------------------------

Note: the sample.zip was actually copied to the m2 local repository as zip-example-0.0.1-SNAPSHOT-optional.zip, hence renamed according to the project configuration (artifactId, version, classifier).