Deploy to Artifactory

Contents

Do you write your own library or framework and want to share it within your team? Then you should deploy your code to your own repository. I use Artifactory as a repository in my profession and I’m totally happy with this solution. Now I like to show you how easy it is to upload your code to the open-source version of Artifactory.

Maven preparations

Add a server

First you have installed the Artifactory[1. If you find it difficult to install Artifactory on Windows, I’ll post on blog on this in the near future] on a server. Then you have to tell Maven where to find it and how to access it. This can be done in your local Maven settings.xml file.

At the beginning you have to add entries for the server. Even with only one physical server you can add as much logical server as you want: one for every repository part (libs-release, libs-snapshot, …). This looks like:

<servers>
    <server>
        <id>central</id>
        <username>username</username>
        <password>{ScpYB6BvO...brZLNpRfQ=}</password>
    </server>
</servers>

The id has to be a unique server name. But has not to be related to an repository name. central is as good as main, libs-release or whatnot. As the username you have to use the name of a repository user. The password looks a little bit weired because it is encrypted. But it is also possible to use the unencrypted password. It’s recommended to use encrypted passwords for security reasons.

Encrypt your password

To encrypt your password you have to follow these 2 steps (also described on maven.apache.org):

Create a master password

Call Maven with mvn --encrypt-master-password <password> to create a password like {jSMOWnoPFgsHVpMvz5VrIt5kRbzGpI8u+9EF1iFQyJQ=}.

Store the encrypted password in ${user.home}/.m2/settings-security.xml:

<settingsSecurity>
  <master>{jSMOWnoPFgsHVpMvz5VrIt5kRbzGpI8u+9EF1iFQyJQ=}</master>
</settingsSecurity>

Create a server password

Call Maven with mvn --encrypt-password <password> and use the encrypted password as shown above.

Add the repository

Still in settingx.xml you have to add some information about your repository:

<profiles>
    <profile>
        <id>artifactory</id>
        <repositories>
            <repository>
                <id>central</id>
                <name>libs-release</name>
                <url>http://<host>:<port>/artifactory/libs-release</url>
            </repository>
        </repositories>
    </profile>
</profiles>
<activeProfiles>
    <activeProfile>artifactory</activeProfile>
</activeProfiles>

You have to include the new repository definition into a profile. In our example we assigned the id “artifactory” to the profile and at the end we activate the profile.

To describe a repository you have to use the server-id as the id and simply use the name of the repository (“libs-release”). On the start page of Artifactory 5.x you can simply click on the repository

artifactory start page

On the next page you can copy-and-paste the repository settings for Maven:

artifactory repository information

Add the repository to your project

At last you have to insert the repository information in your pom.xml:

<distributionManagement>
    <repository>
        <id>central</id>
        <name>libs-release</name>
        <url>http://<host>:<port>/artifactory/libs-release</url>
    </repository>
</distributionManagement>

Deploy your code

Now you can use the goal “deploy” to copy the project artifact (jar) to your Artifactory.

Create sources and JavaDoc

If you also want to deploy jars with the sources and the JavaDoc of your project (common in a lot of projects) you only have to enter the following lines to your pom.xml:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-source-plugin</artifactId>
    <executions>
        <execution>
            <id>attach-sources</id>
            <goals>
                <goal>jar</goal>
            </goals>
        </execution>
    </executions>
</plugin>
<plugin>
    <artifactId>maven-javadoc-plugin</artifactId>
    <executions>
        <execution>
            <id>attach-javadocs</id>
            <goals>
                <goal>jar</goal>
            </goals>
        </execution>
    </executions>
</plugin>

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.