Maven install Plugin: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
(Created page with " !!!External |[Maven Plugin Deploy] !!!Command Line: To install the binary __and__ sources "install" installs into the local repository. {{{ mvn install:install-...")
 
 
(16 intermediate revisions by the same user not shown)
Line 1: Line 1:
=External=


* http://maven.apache.org/plugins/maven-install-plugin/


=Internal=


* [[Maven#Plugin|Maven]]


=Overview=


The install plugin copies artifacts into the ''local repository'' (the [[Maven deploy Plugin|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 [[Maven Concepts - Lifecycle#Overview|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 <tt>mvn install:install</tt> is executed in isolation, the information the plugin needs is not available in the context, so it issues:


!!!External
<pre>
...
[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]
...
</pre>


|[Maven Plugin Deploy]
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:


<pre>
mvn jar:jar deploy:deploy
</pre>


!!!Command Line: To install the binary __and__ sources
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]].


"install" installs into the local repository.
=Examples=


{{{
==Install Arbitrary Files as Binaries and Sources==


<pre>
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 -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
mvn install:install-file -DgroupId=my.group -DartifactId=my-file -Dversion=1.0 -Dpackaging=jar -Dclassifier=sources -Dfile=./my-file-src.jar
</pre>


}}}
==Deploying Programmatically an Artifact under a Different Name than its artifactId==
 
 
!!!Command Line: Deployment
 
"deploy" sends an artifact into a remote repository
 
{{{
mvn deploy:deploy-file -DgroupId=javax.transaction -DartifactId=jta -Dversion=1.0.1B \
-Dpackaging=jar -Dfile="C:\tmp\jta-1.0.1B.jar" \
-Durl="file://C:\Documents and Settings\ofeodoro\.m2" -DrepositoryId=repository
}}}
 
!!!Deploying a third party artifact in http://repository.novaordis.org
 
In order to do that, you will need to log in on {{raiatea}} and become the user {{repository}}.
 
{{{
    /usr/local/maven/bin/mvn deploy:deploy-file -DgroupId=javax.jms -DartifactId=jms -Dversion=1.1 \
                                                -Dpackaging=jar -Dfile=./javax.jms.jar \
                                                -Durl=file:///home/repository/maven2 \
                                                -DrepositoryId=repository.novaordis.org
 
    /usr/local/maven/bin/mvn deploy:deploy-file -DgroupId=javax.jms -DartifactId=jms -Dversion=1.1 \
                                                -Dpackaging=jar -Dclassifier=source -Dfile=./somesourcejar.jar \
                                                -Durl=file:///home/repository/maven2 \
                                                -DrepositoryId=repository.novaordis.org
 
}}}
 
!!!Deploy a third party artifact under an arbitrary group into a remote https:// repository
 
{{{
 
  mvn deploy:deploy-file -DgroupId=ec.template -DartifactId=test -Dversion=1 -Dpackaging=zip \
      -Dfile=./test.zip -Durl=https://A290368:mypasswd@calt.cms.gov/nexus/content/repositories/libs-release-local/blah
 
}}}
 
This will create (with appropriate permissions) https://calt.cms.gov/nexus/content/repositories/libs-release-local/blah/ec/template/test/1/test-1.zip
 
 
!!!Deploying programmatically an artifact under a different name than its artifactId
 
 
The name of the artifact that is being built can be changed with {{&lt;finalName&gt;}} as follows:
{{{
    <build>
            <finalName>simple-webapp</finalName>
    </build>
}}}
or
{{{
    <build>
        <finalName>${artifactId}</finalName>
    </build>
}}}
or
{{{
    <build>     
        <finalName>archimedes-${project.version}</finalName>
    </build>
}}}
or
{{{
    <build>
        <finalName>${parent.artifactId}-${artifactId}</finalName>
    </build>
}}}
 
However, the name won't propagate 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):


{{{
The name of an artifact as created in ./target can be changed using <finalName>. For more details on changing the artifact name see [[Maven_Concepts#Artifact_Name|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>
                <!--
                    Installing the final artifact as "archimedes-*.ear" for convenience; it
                    will be available under 'archimedes' module, not 'ear'.
                -->
                <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>


}}}
<pre>
<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>
</pre>

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>