This section documents configuration and settings specific to Maven based repositories.
Maven Client Configuration¶
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.
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:
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 the Connection Settings of your repository we provide specific configuration information for your repository.
In order for your Maven Client to connect to CloudRepo, you’ll need to configured the following files:
- Project POM Files (pom.xml)
$HOME/.m2 is the default directory for the maven client to use. Please keep this in mind if you’ve changed the location.
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>
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.
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:
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:
Artifacts which are successfully deployed to CloudRepo are immediately available for retrieval and can be seen in the CloudRepo Administrator Portal.
Maven Repository Settings¶
In addition to the Standard Settings associated with every repository, Maven Repositories have the following additional options.
Maven Snapshot Cleanup¶
Maven Snapshots are artifacts whose versions end in -SNAPSHOT.
Each time a snapshot version is deployed to a Maven Repository, a new version of the artifact is written.
Contrast this with release versions, which only have one version in a repository.
If you build your code frequently, you can quickly accumulated dozens or more versions of the same snapshot.
In order to automatically clean this up, you can enable Snapshot Cleanup on your maven repositories.
When enabled, once a day we’ll look at all your snapshot artifacts and remove all but the last X versions of an artifact.