Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to configure Maven2 to publish to Artifactory?

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.

like image 770
IAmYourFaja Avatar asked Jun 09 '14 14:06

IAmYourFaja


People also ask

How do I publish to Artifactory?

Go to the artifact browser, select the repository you want to upload to, and hit the Set Me Up button for instructions. You can upload a file using Artifactory UI. Go to the artifact browser, select the repository you want to upload to, and hit the Upload button for instructions.

How do I configure Maven to publish to Artifactory?

Once you have created your Maven repository, go to Application | Artifactory | Artifacts, select your Maven repository and click Set Me Up. In the Set Me Up dialog, click Generate Maven Settings. You can now specify the repositories you want to configure for Maven.

How do I push jar to JFrog Artifactory?

Upload to the Artifactory repository manually The easiest way, and the least DevOps-friendly way, to upload a JAR to an Artifactory repository is to simply log in to the administrative console, select a target folder and drag and drop the JAR onto the deployment screen.


1 Answers

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).
like image 176
JBaruch Avatar answered Oct 19 '22 20:10

JBaruch