How to configure Maven2 to publish to Artifactory?

IAmYourFaja picture IAmYourFaja · Jun 9, 2014 · Viewed 30.1k times · Source

Currently I have a Maven2 project that builds a JAR when you run:

mvn clean package

I need to now tweak the pom.xml to publish this JAR (myapp.jar) to an Artifactory server running at:

http://myartifactory/artifactory/simple/myorg/myapp/0.1

I tried adding a <repositories> element to my pom.xml but nothing is being published with this config:

<repositories>
    <repository>
        <id>myartifactory</id>
        <url>http://myartifactory/artifactory/simple/</url>
    </repository>
</repositories>

Any ideas as to how I could get publishing to work? For simplicity's sake, pretend that this Artifactory repo is authenticated to accept publishes/writes from a user with a username=foo and password=bar.

Answer

JBaruch picture JBaruch · Jun 10, 2014

You have two options (please note that the later is the recommended one):

Add DistributionManagement part to your pom and server part to your settings.xml

  1. Let's say you want to deploy to libs-snapshot-local repository. In this case you need to go to the tree browser in Artifactory, focus on the repository level, copy the Distribution Management snippet and paste it in your pom.xml: Distribution Managment
  2. Next, you need to tell maven the credentials. For that, click on your username in the top right corner, enter your password to unlock the screen, copy the server tag from Maven Settings panel: enter image description here This one you paste in your settings.xml. Don't forget to replace the ${server-id} with the real server id (the one you have in Distribution Management now).
  3. Now, just run mvn deploy and enjoy.

Working with Maven Artifactory Plugin:

  1. Add the relevant <plugin> part as described in the wiki to your pom.xml. It includes both the target repository and the credentials (please use external credentials source, like environment variables or system properties).
  2. Run mvn deploy and enjoy not only the deployment to Artifactory, but also additional features as described below.

Additional features of Artifactory Maven Plugin (on top of regular Maven deployment):

  1. Allow adding custom properties to the deployed files
  2. Provide the build bill of materials (the buildInfo), allowing Build Integration with any build server (even those not supported by JFrog) or even with standalone builds (without build server at all).