Developers often face the situation that they need to add artifacts manually to a repository manager like the Maven Artifactory. In one of my last projects I also faced this situation. I had to manually add an artifact into a remote repository so that it would be shared with other developers in that project. I solved the task by using the build managing tool maven along with the repository manager maven artifactory.
A repository typically contains more than the artifact itself – POMs, the metadata, MD5 and SHA1 hash files are examples of what could be in the repository as well. To deploy built artifacts you need to add a deployment element in the POM file with the URL of a target local repository to which you want to deploy your artifacts.
<distributionManagement> <repository> <id>snapshot</id> <name>ex-snapshot-local</name> <url>http://localhost:8081/artifactory/ex-snapshot-local</url> </repository> </distributionManagement>
In our Example I needed to deploy a “Model” Project as “jar” file and a “ViewController“ as “war” file. I defined this in a root-POM (workspace POM)
<modules> <module>Model</module> <module>ViewController</module> </modules> <distributionManagement> <repository> <id>snapshot</id> <name>ext-snapshot-local</name> <url>http://localhost:8081/artifactory/ext-snapshot-local</url> </repository> </distributionManagement> <dependencies> <dependency> <groupId>TestApp</groupId> <artifactId>Model</artifactId> <version>1.0-SNAPSHOT</version> <type>jar</type> </dependency> <dependency> <groupId>TestApp</groupId> <artifactId>ViewController</artifactId> <version>1.0-SNAPSHOT</version> <type>war</type> </dependency> </dependencies>
Maven deploy Plugin
The deploy plugin is primarily used during the deploy phase. It can also be used to deploy a particular artifact (e.g. a third party jar like Sun’s non redistributable reference implementations).
Deploying means not only copying the artifacts, but making sure all this information is correctly updated. It’s the responsibility of the deploy plugin that the plugin will be added to the Application-POM.
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-deploy-plugin</artifactId> <version>2.7</version> <configuration> <skip>false</skip> </configuration> </plugin>
To install the Artifact I use “mvn deploy” and my Test-Project will be installed in the Repository Manager – in my case the maven artifactory.