Articles in this section

How to setup Cloudsmith as the default Maven mirror for your dependencies

Intro:

Maven, by default, is configured to pull dependencies from Maven central, this means when building a project and pointing your configuration in pom.xml to Cloudsmith will result in only the main dependencies listed being pulled from Cloudsmith and any dependencies of that dependency will usually get pulled from Maven Central:

How to point your mirror to Cloudsmith:

NOTE: It is important to note that this will result in the token being exposed in plaintext and exposed during any mvn command that forces a pull of dependencies. In order to ensure safety, Cloudsmith highly recommends consulting Maven’s official documentation for encrypting passwords.

 

One important thing to remember is that the repository will require all of the packages and their dependencies to be present in the repository, this either means that the packages need to be manually uploaded to the repository or make use of our upstream functionality (To find out how to create an upstream, follow this 2-step guide). 

 

Once the necessary packages are in the repository and/or Maven upstream is created, navigate to the following directory in your system:

 

There are two locations where a settings.xml file may live:

  • The Maven install: ${maven.home}/conf/settings.xml
  • A user's install: ${user.home}/.m2/settings.xml

If you are having trouble locating the folder, please consult Maven’s official documentation.

Follow the following steps:

  • If the settings.xml file does not exist, create one, otherwise open in an editor of choice
  • If the file has no configuration present, copy and paste the following template, if settings are present, comment out/replace the <mirrors> content with the one provided in the example:
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
https://maven.apache.org/xsd/settings-1.0.0.xsd">

<mirrors>
<mirror>
<id>cloudsmith-REPO-NAME</id>
<name>cloudsmith-REPO-NAME</name>
<url>CLOUDSMITH-URL</url>
<mirrorOf>*</mirrorOf>
</mirror>
</mirrors>

</settings>
  • Navigate to your Cloudsmith repository that you have your dependencies/upstreams configured and click on Set me up -> Maven:

  • Select the entitlement token that you wish to authenticate with
  • Under Build System Setup, ensure that Maven is selected and copy the URL address from the URL tag in the example .pom file and overwrite the CLOUDSMITH-URL placeholder.
  • Fill in the <id> and <name> tags. (The recommended naming convention would be cloudsmith-<repo>-<name>)
  • An example of filled-in settings.xml:
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
https://maven.apache.org/xsd/settings-1.0.0.xsd">
<mirrors>
<mirror>
<id>cloudsmith-maven-dev</id>
<name>cloudsmith-maven-dev</name>
<url>https://dl.cloudsmith.io/<TOKEN>/cloudsmith/maven-dev/maven/</url>
<mirrorOf>*</mirrorOf>
</mirror>
</mirrors>
</settings>

 

You should now be set to use Cloudsmith as your default Maven mirror 🎊

Was this article helpful?
0 out of 0 found this helpful

Comments

0 comments

Please sign in to leave a comment.