JFrog Artifactory and Maven Package Type

V Niranjan
8 min readJan 8, 2023

--

As a project team you need a repository to store your Build Artifacts and its versions. JFrog Artifactory is the repository manager which helps to store the all the artifacts be it binaries or the dependencies or any kind of configuration files.

JFrog Artifactory supports multiple package types as shown below to securely store all the artifacts produced by these package types.

Artifactory Package Types

JFrog Artifactory is a single source of truth for securely storing all of your development artifacts and a very important component of any CI/CD tool. You can think of Artifactory as a binding force between the developers and any external resources. Artifactory provides quick access to remote artifacts using remote repository concept wherein they are cached locally. So a developer is actually re-directed to Artifactory only for access to remote artifacts as they are cached locally in remote repository.

In this article we will look at using Artifactory for Maven package type. The article assumes you have the SAAS version of Artifactory.

1. Types of repositories in JFrog Artifactory

A repository in Artifactory stores the artifacts of all package formats as shown in the introduction. A repository can be a source which holds all artifacts needed for any build and also a target to store the artifacts generated out of build.

Artifactory supports the following types of repositories:

Ø Local repository : Central location to store your artifacts generated by builds

Ø Remote repository: Cache of a repository which is managed at remote. You cannot deploy to a remote repository. Remote repository provides faster access to dependencies stored in remote URL. Issues such as network latency, poor connectivity to remote sites, downtimes can be avoided with the use of remote repository

Ø Virtual repository: Combination of both local and remote repositories having a common end point

Ø Federated repository: This type of repository is used in multisite kind of environment allowing mirror of artifacts to another Federated repository site located remotely. You can think of Federated repository as a kind of local repository only.

Typically when using a Federated repository setup it is suggested to use JFrog Artifactory repositories in the below way.

Virtual Repository = Federated repository + Remote repository

Usage of Virtual repository will give you one URL endpoint to download dependencies and deploy artifacts as well.

In this article we will use a Maven type Virtual Repository.

2. Create Maven Local repository

Local repository is a central location to store your artifacts generated by builds. To create a local repository as an Admin user select Administration TAB → Repositories. Now click on + Add Repository in the top right and select Local Repository.

Select Maven package type. Provide a repository key

Click on Create Local Repository.

Go to the Application TAB → Artifacts to search for the repository just created.

3. Create Maven Remote Repository

Remote repository is a cache of a repository which is managed at remote. Let’s look at how to create the maven remote repository.

As an Admin user select Administration TAB → Repositories. Now click on + Add Repository →Remote Repository in the top right. Select Maven.

Provide a repository key and leave the remote URL as is. Click on Test. You see a successful connection message at the top.

Click on Create Remote Repository. The remote repository should be now available in the list.

4. Create Maven Virtual Repository

Virtual repository is a Combination of both local and remote repositories having a common end point

As an Admin user select Administration TAB →Repositories. Now click on + Add Repository →Virtual Repository in the top right. Select Maven.

Provide a Repository key and scroll down to add both local and remote repositories. Also setup the Default Deployment repository to local repository.

Click on Create Virtual Repository. The virtual repository should now be available.

5. User Management and Tokens

Before we look at a Maven example let’s look at how User Management and Tokens in Artifactory can be managed from the Administration Tab. As you login to the Artifactory URL go to the Administration TAB.

Now click on the User Management →Users

Click on + New user

Enter a Username, email and password (scroll below to provide the same)

If the user is supposed to be Admin then click on the role Administer Platform. Click on Save. We have still not provided access of any repository for the user. To do this we need to create Permission Target.

Create Permission Target (Providing access to repository)

In the Administration Tab click on Permissions under User Management.

Click on +New Permission . Provide a name and click on + Add Repositories.

Select the Local Repository (Maven) created in previous section. Click on Ok.

Click on the Users Tab and + under Selected Users

Click Ok once you select all users.

Select the appropriate permissions under Repositories section and click on Create.

Admin users will have access to all repositories by default. Now the users can login and start accessing the repositories. Normally if SAML Single Sign On is enabled then users will login with their corporate ID and Password. More about configuring SAML for your JFrog site can be found @ SAML SSO — JFrog — JFrog Documentation

Creating Identity Token

Creating any kind of token provides a flexible way of authentication. We will look at how it can be used especially in pipelines or login using docker.

Go to the User Profile →Edit Profile

Unlock your profile using the password.

Click on Generate an Identity Token.

Copy and Save the token. These tokens can be used instead of passwords.

6. JFrog Artifactory Maven Example

In this section we will look at how to how to compile and upload Maven artifacts to the Maven local repository while using the dependencies from the Maven remote repository for compile.

To setup, as a user go to Application TAB →Artifactory →Artifacts. Search for the Virtual repository and click on Set Me Up.

Setup the values as shown below and click on Generate Settings.

You can download the snippet or copy the text to the settings.xml which is in the ~/.m2 directory.

Here is the modified settings.xml file. Ensure to update the text in GREEN for your settings.

The Encrypted password which is needed for settings.xml file can be found from your User profile.

Sample settings.xml file

— — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — -

<?xml version=”1.0" encoding=”UTF-8"?>

<settings xsi:schemaLocation=”http://maven.apache.org/SETTINGS/1.2.0 http://maven.apache.org/xsd/settings-1.2.0.xsd" xmlns=”http://maven.apache.org/SETTINGS/1.2.0"

xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance">

<servers>

<server>

<username>niranjan</username>

<password>Insert-Encrypted-PWD</password>

<id>central</id>

</server>

<server>

<username>niranjan</username>

<password> Insert-Encrypted-PWD </password>

<id>snapshots</id>

</server>

</servers>

<profiles>

<profile>

<repositories>

<repository>

<snapshots>

<enabled>false</enabled>

</snapshots>

<id>central</id>

<name>niranjan-maven-virtual</name>

<url>https://<SAAS-URL>.jfrog.io/artifactory/niranjan-maven-virtual</url>

</repository>

<repository>

<snapshots />

<id>snapshots</id>

<name>niranjan-maven-virtual</name>

<url>https://<SAAS-URL>.jfrog.io/artifactory/niranjan-maven-virtual</url>

</repository>

</repositories>

<pluginRepositories>

<pluginRepository>

<snapshots>

<enabled>false</enabled>

</snapshots>

<id>central</id>

<name>niranjan-maven-virtual</name>

<url>https://<SAAS-URL>.jfrog.io/artifactory/niranjan-maven-virtual</url>

</pluginRepository>

<pluginRepository>

<snapshots />

<id>snapshots</id>

<name>niranjan-maven-virtual</name>

<url>https://<SAAS-URL>.jfrog.io/artifactory/niranjan-maven-virtual</url>

</pluginRepository>

</pluginRepositories>

<id>artifactory</id>

</profile>

</profiles>

<activeProfiles>

<activeProfile>artifactory</activeProfile>

</activeProfiles>

</settings>

— — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — —

Go back to the Set Me Up for the virtual repository and go to the Deploy tab. Copy the contents to the pom.xml file which will be used to upload the maven artifacts to the local repository.

REMEMBER TO USE YOUR ARTIFACTORY URL’S.

Now run the command to Build and Deploy as below.

mvn clean install

The dependencies downloaded are from the JFrog Artifactory remote repository.

Now run the below command to deploy the artifacts to the local repository.

mvn deploy

Now look at the Local repository for the artifacts deployed which was configured as the default deployment repository.

Well the Maven commands can also be called from your CI/CD pipeline using Jenkins or any other CI/CD tool.

7. Summary

So we did see an example of how to use Artifactory for Maven package type in your build and deploy process. Hope you found it useful. I will try and add examples for more package types in the next articles.

Thank you.

--

--

V Niranjan

I am a software professional focusing on Agile Scrum using Jira/Confluence/Jenkins/Sonarcloud/GitHub/GitHub Copilot/Artifactory/Docker and other DevOps tools.