Maven Configuration

Overview

Apache Maven repositories are where software development teams share their code artifacts (libraries, packages, etc.).

Maven Central is the public repository where open source and other publicly available artifacts can be downloaded.

However, many businesses, private organizations and projects require private maven repositories so that they can leverage the power of Maven while maintaining the privacy of their artifacts.

CloudRepo is a private, cloud based, artifact repository which provides both public and private Maven repositories to its users.

This page will help you get started by helping you setup a CloudRepo Maven repository.

Pre-Requisites

Before you can use CloudRepo with Maven you’ll need to ensure that you have created a Maven Repository as well as a Repository User in the CloudRepo Admin Portal.

If you haven’t done this yet, please see the following instructions for doing so:

Note

For security purposes (mostly because passwords tend to be stored in plaintext), we do not allow your admin user to access artifacts via the repositories. Please create a user in the CloudRepo Administrator Portal.

Maven Client Settings

In order for your Maven Client to connect to CloudRepo, you’ll need to configured the following files:

  • $HOME/.m2/settings.xml
  • Project POM Files (pom.xml)

Note

$HOME/.m2 is the default directory for the maven client to use. Please keep this in mind if you’ve changed the location.

settings.xml

In order for your Maven Client to connect to CloudRepo, you’ll need to add a <server> entry to the settings.xml the user’s authentication information to your Maven settings.xml file, usually located in the $HOME/.m2 directory.

An example settings.xml is below:

<settings>
  <servers>
    <server>
      <!-- id is a unique identifier for a single repository.-->
      <id>io.cloudrepo</id>
      <!-- Email Address of the Repository User -->
      <username>repository-user-email-address</username>
      <!-- Password of the Repository User -->
      <password>repository-user-password</password>
    </server>
  </servers>
</settings>

See also

Security Tip: You should consider encrypting the repository users’ password following these instructions from the official Maven Documentation.

Project POM Files (pom.xml)

All Maven projects use a Project Object Model (POM) file to specify the location of the repositories to read and write artifacts to/from.

Configuration of the POM file for downloading artifacts is distinct from publishing artifacts. Examples for both are specified below.

Note

Specify your repositories in the parent POM file (if you have one) so that you only have to add the repository information in a single place.

Retrieving Artifacts from CloudRepo

Repositories specified in the <repositories> block define the repositories that Maven will use to retrieve artifacts.

<project>
  <!-- ...  -->
  <!-- Other Project Configuration (dependencies, etc.)-->
  <!-- ...  -->
  <repositories>
    <repository>
      <!--
      The username and password are retrieved by looking for the Repository
      Id in the $HOME/.m2/settings.xml file.
      -->
      <!-- id Must Match the Unique Identifier in settings.xml -->
      <id>io.cloudrepo</id>
      <url>https://[your-org-name].mycloudrepo.io/repositories/[your-repository-name]</url>
      <releases/>
    </repository>
  </repositories>
</project>

After the repository has been configured, Maven will retrieve your artifacts stored in CloudRepo as part of its build process.

One way to trigger a maven build is to execute the following command in the same directory as your POM file:

mvn install

Publishing Artifacts to CloudRepo

Repositories listed in the <distributionManagement> section of the POM file define the repositories that Maven will use to publish artifacts.

<project>
  <!-- All your other configuration -->
  <distributionManagement>
    <repository>
      <id>io.cloudrepo</id> <!-- Must Match the Unique Identifier in settings.xml -->
      <name>My First Cloud Repo Repository</name>
      <url>https://[your-org-name].mycloudrepo.io/repositories/[your-repository-name]</url>
    </repository>
  </distributionManagement>
</project>

After your distribution repository has been properly configured, you can publish artifacts to CloudRepo with the following command:

mvn deploy

Artifacts which are successfully deployed to CloudRepo are immediately avaialble for retrieval and can be seen in the CloudRepo Administrator Portal.