How to Deploy Maven Artifacts to CloudRepo via Rultor
In my previous article, I described how to set up a private Maven repository in Amazon S3 and deploy there via Rultor. This is a great solution if you’re familiar with managing Amazon Web Services (AWS), S3, and AWS Identity and Access Management (IAM). However, if you’re not comfortable administering an AWS account and all the related permissions, you may want to store your Apache Maven Artifacts in some cloud based repository manager instead. Here is how you make Rultor deploy your Maven dependencies to CloudRepo. I wrote this blog post together with Chris Shellenbarger, their founder.
Both repository managers and S3 will allow your build tools to store and retrieve your software libraries in a remote repository or bucket. However, repository managers take care of a lot of the work that you’d have to manage yourself with the S3 solution.
While AWS is quite robust and can be configured to do everything a repository manager can, there are use cases that work directly out of the box when you choose a fully managed solution, like: User/Group Administration, Maven Specific Views, Webhooks, Notifications, Access and Audit Logs, Fully Managed Security, etc. Simply put, they are not just storages of JAR files, but Maven repositories in cloud.
Assuming you have created an account with CloudRepo and setup both a user and maven repository, deploying to CloudRepo requires two steps on the client side: 1) Configure a settings.xml
file with credentials, and 2) Add your repository to your pom.xml
file’s <distributionManagement>
section.
The default location for the settings.xml
file is in your ~/.m2
directory. Edit this file and ensure that you have a <server>
entry as seen below:
1 2 3 4 5 6 7 8 9 | <settings> <servers> <server> <id>io.cloudrepo</id> <username>yegor256 @gmail .com</username> <password>my-secret</password> </server> </servers> </settings> |
By declaring a server
and specifying an id
, you can reference the id
from within your Maven POM files. When Maven attempts to authenticate against a server it will look for a corresponding key in the settings.xml
file.
If you’re worried about storing your password in plaintext on your filesystem, check how Maven recommends fixing that.
Now that your credentials have been set, you must point your pom.xml
at your CloudRepo repository. Add a new <repository>
element to the <distributionManagement>
(to upload them) section of your pom.xml
and to the <repositories>
(to download them):
01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 | <project> [...] <repositories> <repository> <id>io.cloudrepo</id> <url>https: //[your-org-name].mycloudrepo.io/repositories/[your-repository-name]</url> </repository> </repositories> [...] <distributionManagement> <repository> <id>io.cloudrepo</id> <name>CloudRepo Maven Repository</name> <url>https: //[your-org-name].mycloudrepo.io/repositories/[your-repository-name]</url> </repository> </distributionManagement> </project> |
Once you have a build working in your local environment, you need to deploy it to production with Rultor. First, you’ll need to store your credentials in Git so that Rultor can access them at build and deploy time. However, it is very important to never store your credentials in plaintext in version control (substitute the name of your GitHub project with my/project
):
1 2 | $ gem install rultor $ rultor encrypt -p my/project settings.xml |
This creates an encrypted version of your settings file with the name settings.xml.asc
. Add this file to the root directory of your project, then commit and push. It is safe. Only Rultor has the keys to decrypt this file so even if your source code is exposed to others, your credentials will be kept safe.
To enable Rultor, add a .rultor.yml
file to the root directory of your project with the following contents:
1 2 3 4 5 | decrypt: settings.xml: "repo/settings.xml.asc" deploy: script: | mvn clean deploy --settings ../settings.xml |
For more information on the .rultor.yml
file, check the Rultor Reference Page.
Now that everything is configured you should be able to deploy to CloudRepo with Rultor by executing the @rultor deploy
command. Wait for the response and Rultor will take care of all the rest.
That’s it!
Published on Java Code Geeks with permission by Yegor Bugayenko, partner at our JCG program. See the original article here: How to Deploy Maven Artifacts to CloudRepo via Rultor Opinions expressed by Java Code Geeks contributors are their own. |