Maven install Plugin

From NovaOrdis Knowledge Base
Revision as of 17:30, 18 November 2016 by Ovidiu (talk | contribs) (→‎Overview)
Jump to navigation Jump to search

External

Internal

Overview

The install plugin copies artifacts into the local repository (the deploy plugin copies artifacts into a remote repository). It uses the information in the POM (groupId, artifactId, version) to determine the proper location for the artifact within the local repository. It can also be used as a detached tool to copy arbitrary files into the repository.

Running as Part of a Lifecycle

When the install plugin is running as part of the lifecycle, the information about files to copy are gathered by the previous phases (packaging, actually) and placed in the context. This is how the install plugin knows exactly what to copy. When mvn install:install is executed in isolation, the information the plugin needs is not available in the context, so it issues:

...
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-install-plugin:2.4:install (default-cli) on project nort: The packaging for this project did not assign a file to the build artifact -> [Help 1]
...

Examples

Install Arbitrary Files as Binaries and Sources

mvn install:install-file -DgroupId=my.group -DartifactId=my-file -Dversion=1.0 -Dpackaging=jar -Dfile=./my-file.jar
mvn install:install-file -DgroupId=my.group -DartifactId=my-file -Dversion=1.0 -Dpackaging=jar -Dclassifier=sources -Dfile=./my-file-src.jar

Deploying Programmatically an Artifact under a Different Name than its artifactId

The name of an artifact as created in ./target can be changed using <finalName>. For more details on changing the artifact name see Artifact Name. However, the name won't propagate to the local or remote repository upon installation or deploy. To install the artifact under a different name, do the following (please be aware that the artifact won't be deployed under the current module's directory, but under whatever is specified as "artifactId" below):

<plugin>
    <artifactId>maven-install-plugin</artifactId>
     <executions>
         <execution>
             <id>install-ear-as-archimedes</id>
             <phase>install</phase>
             <configuration>
                 <file>${project.build.directory}/${project.build.finalName}.ear</file>
                 <groupId>com.numberdog.archimedes</groupId>
                 <artifactId>archimedes</artifactId>
                 <version>${parent.version}</version>
                 <packaging>ear</packaging>
             </configuration>
             <goals>
                 <goal>install-file</goal>
             </goals>
         </execution>
     </executions>
</plugin>