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
).
.zip
file is part of thetarget
folder content, but is it copied to the localm2
cache? I presume not, only the.jar
should be there, consistently with thedeploy
behavior then. Can you share more of the concernedpom.xml
file? Most probably thezip
file is generated by not attached to the build as additional artifact - A_Di-Matteo.jar
in localm2 cache
. I just have special plugincustom-plugin-packaging-zip
And this plugin make for mezip
file intarget
folder. How I can attach this to build as additional artifact? - Artur Ganiev