Maven install Plugin: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
 
(4 intermediate revisions by the same user not shown)
Line 27: Line 27:
</pre>
</pre>


The [[Maven jar Plugin|jar plugin]] invoked via jar:jar will not re-create any JAR as part of its execution, because its <tt>forceCreation</tt> option is set to false by default. The jar plugin populates the build context with the information install needs.
The [[Maven jar Plugin|jar plugin]] invoked via jar:jar will not re-create any JAR as part of its execution, because its [[Maven_jar_Plugin#forceCreation|forceCreation]] option is set to false by default. The jar plugin populates the build context with the information install needs.


The same considerations apply to the [[Maven deploy Plugin|deploy plugin]].
The same considerations apply to the [[Maven deploy Plugin|deploy plugin]].

Latest revision as of 06:00, 9 January 2018

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

There are situations when we would prefer to only exercise the install functionality, in top of artifacts that were already built. This can be done as follows:

mvn jar:jar deploy:deploy

The jar plugin invoked via jar:jar will not re-create any JAR as part of its execution, because its forceCreation option is set to false by default. The jar plugin populates the build context with the information install needs.

The same considerations apply to the deploy plugin.

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>