Installing Secondary Artifacts

Sometimes you need to install secondary artifacts after the main artifact has been installed in your local repository. To install a secondary artifact you need to use the classifier parameter to classify the secondary artifact.

Let us assume that you want to install the sources for an old artifact, like commons-logging-1.0.3. The central repository only has the main artifact and a -javadoc artifact for that version. Package up the sources into a JAR file on your local disk and then run the following command:

mvn org.apache.maven.plugins:maven-install-plugin:3.0.0:install-file  -Dfile=path-to-commons-logging-sources.jar \
                                                                              -DgroupId=commons-logging \
                                                                              -DartifactId=commons-logging \ 
                                                                              -Dversion=1.0.3 \
                                                                              -Dpackaging=jar \
                                                                              -Dclassifier=sources

Note: By using the fully qualified path of a goal, you're ensured to be using the preferred version of the maven-install-plugin. When using mvn install:install-file its version depends on its specification in the pom or the version of Apache Maven.