JFrog Artifactory Tutorial: Introduction and Maven Package Type

By Sruthy

By Sruthy

Sruthy, with her 10+ years of experience, is a dynamic professional who seamlessly blends her creative soul with technical prowess. With a Technical Degree in Graphics Design and Communications and a Bachelor’s Degree in Electronics and Communication, she brings a unique combination of artistic flair…

Learn about our editorial policies.
Updated June 27, 2024
Edited by Kamila

Edited by Kamila

Kamila is an AI-based technical expert, author, and trainer with a Master’s degree in CRM. She has over 15 years of work experience in several top-notch IT companies. She has published more than 500 articles on various Software Testing Related Topics, Programming Languages, AI Concepts,…

Learn about our editorial policies.

This introductory tutorial will explain everything that you need to know about JFrog Artifactory. Discover more about Maven Package Type and its usage with simple examples:

As a project team, you need a repository to store your Build Artifacts and their versions. JFrog Artifactory is the repository manager that helps to store all the artifacts be they binaries or 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. The most common ones that I have used are Maven, Docker, and NPM.

=> SCROLL DOWN to See the List of In-Depth JFrog Tutorials in this Series

JFrog Artifactory: A Complete Guide

Introduction and Maven Package type1

List of Tutorials in this JFrog Series:

Tutorial #1: JFrog Artifactory Tutorial: Introduction and Maven Package Type (This Tutorial)
Tutorial #2: Create Generic, Python and Docker Package Repositories
Tutorial #3: NPM Package Type and Jenkins Integration
Tutorial #4: Working with Gradle and GO Package Type
Tutorial #5: PHP Composer, NuGet and Gems Package Type in JFrog Artifactory
Tutorial #6: Setup of RPM and Debian Repositories
Tutorial #7: General Administration Activities in JFrog Artifactory
Tutorial #8: JFrog Artifactory Query Language (AQL)REST API and Command Line Interface (CLI)


What is JFrog Artifactory?

JFrog Artifactory is a single source of truth for securely storing all of your development artifacts and is 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 the remote repository concept wherein they are cached locally. So a developer is redirected to Artifactory only for access to remote artifacts as they are cached locally in the remote repository.

Build Artifacts

In this JFrog series, we will look at the following topics:

  • Where does Artifactory fit in the CI process
  • Types of repositories (Local, Remote, Virtual, and Federated)
  • Creating repositories
  • User Management and Tokens
  • Property Set
  • Using Artifactory for Maven, Generic, Docker, NPM, Gradle, and GO package types
  • Integration with Jenkins

Here, we have used the JFrog Artifactory SAAS/Cloud trial version to demonstrate the above. The 14-day trial version can be requested from the link Start For Free With Artifactory and Xray | JFrog.

Once you sign up, a user with admin privileges will be created. This article will be focussed on using the Maven package type example in JFrog Artifactory

Where Does Artifactory Fit in the CI Process

As we know Artifactory is a very important component of the Continuous Integration (CI) process, the below diagram will give an idea. Artifactory is integrated with most of the major CI tools.

Where does Artifactory fit in the CI process

Types of Repositories

A repository in Artifactory stores the artifacts in all package formats as shown in the introduction. A repository can be a source that holds all artifacts needed for any build and also a target to store the artifacts generated out of the 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 that is managed remotely. You cannot deploy to a remote repository. The remote repository provides faster access to dependencies stored in remote URLs. Issues such as network latency, poor connectivity to remote sites, and downtimes can be avoided with the use of the remote repository.
  • Virtual Repository: Combination of both local and remote repositories having a common endpoint.
  • Federated Repository: This type of repository is used in a multisite kind of environment allowing the mirror of artifacts to another Federated repository site located remotely. You can think of a 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 a Virtual repository will give you one URL endpoint to download dependencies and deploy artifacts as well.

In this article, for all examples, we will use Virtual Repository = Local repository + Remote repository.

Create Maven Local Repository

A 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.

Create Maven Local repository

Select Maven package type.

Select Maven package type

Provide a repository key.

Provide a repository key

Click on Create Local Repository.

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

Click on Create Local Repository

Create Maven Remote Repository

A remote repository is the cache of a repository that is managed remotely. Let’s look at how to create a Maven remote repository.

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

Create Maven Remote Repository
Jfrog platform1

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

Provide a repository key 1

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

Click on Create Remote Repository

Create Maven Virtual Repository

A virtual repository is a combination of both local and remote repositories having a common endpoint

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

Create Maven Virtual Repository
Provide a Repository key 1

Provide the Repository key and scroll down to add both local and remote repositories. Also, set up the Default Deployment repository for the local repository.

local and remote repositories
Default Deployment repository

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

Click on Create Virtual Repository

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. Once you log in to the Artifactory URL go to the Administration TAB.

Administration TAB1

Now click on User Management -> Users

User Management

Click on + New user

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

New user

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

Create Permission Target (Providing access to repository)

In the Administration Tab, click on Permissions under User Management.

Providing access to repository

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

New Permission

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

Select the Local Repository (Maven)
Local Repository (Maven) created

Click OK.

Click on the Users Tab and + under Selected Users

under Selected Users
Users Tab

Click OK once you select all users.

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

Select the appropriate permissions

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

Creating an 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 logins using Docker.

Go to the User Profile. Edit Profile

Repositories section and click on Create

Unlock your profile.

Unlock your profile

Click on Generate an Identity Token.

Generate an Identity Token
Copy and Save the token

Copy and Save the token.

Property Sets

Typically, when you want to tag a repository, you can use Property sets to define a property of single or multiple values. Property sets can also be used in locating items.

For e.g. You can tag the repository being used exclusively in Indian or European locations so that the teams have the clarity to upload any artifacts appropriately.

To create a Property set, go to Admin Tab -> Services -> Artifactory  -> General  -> Property Sets

Property Sets

Click on New Property Set.

Click on New Property Set

Provide a name and click on New Record.

New Record

Add a Property Name using a Single Select value and click on Save.

Add a Property Name

Click on Save on the main Property Set screen.

Click on Save in the main Property Set screen

Assigning Property set to Repository

To assign a Property set to a repository, go to Administration Tab -> Repositories. Go to the Advanced Tab of the repository and add the property set just created. Click on Save once done.

Repositories

Apply the Property Set and value to a Local Repository

Go to the Application TAB, click on the local repository, and click on Properties -> Property set sub-tab. You need not be an Admin to perform the below steps.

Property set sub tab

Select the Property set and value and click on Add. Selecting Recursive will add to all folders and artifacts under the repository. The final view is shown below after selecting the Property set and values.

Add

JFrog Artifactory Maven Example

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

To set up, a user goes to Application TAB -> Artifactory -> Artifacts. Search for the Virtual repository and click on Set Me Up.

JFrog Artifactory Maven Example

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

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.

Encrypted password which is needed for settings.xml files can be found in your User profile.

The Encrypted password
<?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://vniranjan25.jfrog.io/artifactory/niranjan-maven-virtual</url>
      </repository>
      <repository>
      <snapshots>
        <enabled>false</enabled>
      </snapshots>
      <id>central</id>
      <name>niranjan-maven-virtual</name>
        <url>https://vniranjan25.jfrog.io/artifactory/niranjan-maven-virtual</url>
      </repository>
      <repository>
       <snapshots />
        <id>snapshots</id>
          <name>niranjan-maven-virtual</name>
          <url>https://vniranjan25.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://vniranjan25.jfrog.io/artifactory/niranjan-maven-virtual</url>
  </pluginRepository>
  <pluginRepository>
  <snapshots />
  <id>snapshots</id>
<name>niranjan-maven-virtual</name>
   <url>https://vniranjan25.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 content to the pom.xml file which will be used to upload the maven artifacts to the local repository.

Deploy tab
run the command to Build and Deploy

Now run the command below to Build and Deploy as below.

mvn clean install

mvn deploy

The dependencies downloaded are from the JFrog Artifactory remote repository.

mvn deploy

configured

Now, look at the Local repository which was configured as the default deployment repository.

Local repository

Conclusion

In this tutorial, we looked at what Artifactory is, how it fits into the CI process, different repository types, and its usage along with what is a property set. This article focused on the Maven Package type with an example.

In the next part of the series, we will look at how to use JFrog Artifactory for Generic, Python, and Docker Package types along with using the Artifactory plugin in Jenkins.

NEXT Tutorial

Was this helpful?

Thanks for your feedback!

Leave a Comment