Revision #1 on Oct 20th, 2023: Added section with steps to use the dependencies you deployed to a Maven repository hosted in an Azure Blob Storage Container.

1. OVERVIEW

Microsoft Azure Blob Storage is a low-cost option to store your Maven or other binary artifacts. It’s an alternative to feature-rich Maven repository managers like Nexus, Artifactory when you don’t have the resources to install and maintain a server with the required software or the budget to subscribe to a hosted plan.

A choice I wouldn’t recommend is to store your artifacts in the SCM.

Deploying a Maven snapshot artifact to an Azure Blog Storage Container

This tutorial covers configuring Maven and setting up the Azure Blob Storage infrastructure to deploy your Java artifacts to; as well as the Maven configuration to include them in other applications.

2. SETUP AZURE BLOB STORAGE COMPONENTS

Login with your existing Azure account or Sign up to create a new one.

2.1. CREATE STORAGE ACCOUNT

Once you login, you would need to Creare a Storage Account.

  • First create a new Resource Group.

Creating a Resource Group Creating a Resource Group

  • Then continue creating a Storage Account.

Creating an Azure Storage Account Creating an Azure Storage Account

After validation and creation, you should now have a Storage Account.

2.2. CREATE STORAGE ACCOUNT CONTAINERS

  • Browse to the Account’s Containers.

Listing Account Containers Account Containers

  • Click on the + Container button to create the snapshot Container.

Creating an Account Container

  • Repeat the previous step to create the release Container.

3. CONFIGURING MAVEN AND APPLICATION TO BE DEPLOYED TO A STORAGE CONTAINER

Include these updates on the Maven and application side:

  • settings.xml
...
<servers>
  <server>
    <id>maven-repo-tutorial.asimio.net</id>
    <username>mavenrepotutorial</username>
    <password>${azure-storage-user-secret-key}</password>
  </server>
</servers>
...

You could add these server settings in your existing ~/.m2/settings.xml or in a new file as done in this tutorial.

Server property Value Description
id maven-repo-tutorial.asimio.net Identifier used in the repository and snapshotRepository configured in pom.xml.
username mavenrepotutorial The name used when creating the Storage Account.
password XXXX The Storage Account Access Key you can get from the next image. Don’t make this value public.


Storage Account Access Key Storage Account Access Key

Let’s now configure the artifact’s pom.xml:

  • pom.xml
<build>
...
  <extensions>
    <extension>
      <groupId>com.gkatzioura.maven.cloud</groupId>
      <artifactId>azure-storage-wagon</artifactId>
      <version>1.8</version>
    </extension>
  </extensions>
...
</build>
...
<distributionManagement>
  <snapshotRepository>
    <id>maven-repo-tutorial.asimio.net</id>
    <url>bs://mavenrepotutorial/snapshot</url>
  </snapshotRepository>
  <repository>
    <id>maven-repo-tutorial.asimio.net</id>
    <url>bs://mavenrepotutorial/release</url>
  </repository>
</distributionManagement>
...

Notice these ids match the one from settings.xml.
Also notice the urls match the Azure Storage Account name (mavenrepotutorial) and each Storage Container name (snapshot, release).

azure-storage-wagon is a Maven Wagon for Azure Storage, used to publish artifacts to a Storage Account.

4. DEPLOYING AN ARTIFACT TO A STORAGE CONTAINER

4.1. DEPLOYING A SNAPSHOT

mvn --settings settings.xml clean deploy -Dazure-storage-user-secret-key=XXXX
...
[INFO] --- maven-deploy-plugin:2.8.2:deploy (default-deploy) @ springboot-togglz-demo ---
Downloading from maven-repo-tutorial.asimio.net: bs://mavenrepotutorial/snapshot/com/asimio/demo/springboot-togglz-demo/0-SNAPSHOT/maven-metadata.xml
Uploading to maven-repo-tutorial.asimio.net: bs://mavenrepotutorial/snapshot/com/asimio/demo/springboot-togglz-demo/0-SNAPSHOT/springboot-togglz-demo-0-20200831.221412-1.jar
Uploaded to maven-repo-tutorial.asimio.net: bs://mavenrepotutorial/snapshot/com/asimio/demo/springboot-togglz-demo/0-SNAPSHOT/springboot-togglz-demo-0-20200831.221412-1.jar (31 MB at 1.4 MB/s)
Uploading to maven-repo-tutorial.asimio.net: bs://mavenrepotutorial/snapshot/com/asimio/demo/springboot-togglz-demo/0-SNAPSHOT/springboot-togglz-demo-0-20200831.221412-1.pom
Uploaded to maven-repo-tutorial.asimio.net: bs://mavenrepotutorial/snapshot/com/asimio/demo/springboot-togglz-demo/0-SNAPSHOT/springboot-togglz-demo-0-20200831.221412-1.pom (5.0 kB at 24 kB/s)
Downloading from maven-repo-tutorial.asimio.net: bs://mavenrepotutorial/snapshot/com/asimio/demo/springboot-togglz-demo/maven-metadata.xml
Uploading to maven-repo-tutorial.asimio.net: bs://mavenrepotutorial/snapshot/com/asimio/demo/springboot-togglz-demo/0-SNAPSHOT/maven-metadata.xml
Uploaded to maven-repo-tutorial.asimio.net: bs://mavenrepotutorial/snapshot/com/asimio/demo/springboot-togglz-demo/0-SNAPSHOT/maven-metadata.xml (1.6 kB at 8.3 kB/s)
Uploading to maven-repo-tutorial.asimio.net: bs://mavenrepotutorial/snapshot/com/asimio/demo/springboot-togglz-demo/maven-metadata.xml
Uploaded to maven-repo-tutorial.asimio.net: bs://mavenrepotutorial/snapshot/com/asimio/demo/springboot-togglz-demo/maven-metadata.xml (586 B at 2.9 kB/s)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
...

Deploying a Maven snapshot artifact to an Azure Storage Container Deploying a Maven snapshot artifact to an Azure Storage Container

4.2. DEPLOYING A RELEASE

mvn clean versions:set -DnewVersion=1.0.15
...
[INFO] Processing change of com.asimio.demo:springboot-togglz-demo:0-SNAPSHOT -> 1.0.15
[INFO] Processing com.asimio.demo:springboot-togglz-demo
[INFO]     Updating project com.asimio.demo:springboot-togglz-demo
[INFO]         from version 0-SNAPSHOT to 1.0.15
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
...

This command updates the version of the artifact.

mvn --settings settings.xml clean deploy -Dazure-storage-user-secret-key=XXXX
...
[INFO] --- maven-deploy-plugin:2.8.2:deploy (default-deploy) @ springboot-togglz-demo ---
Uploading to maven-repo-tutorial.asimio.net: bs://mavenrepotutorial/release/com/asimio/demo/springboot-togglz-demo/1.0.15/springboot-togglz-demo-1.0.15.jar
Uploaded to maven-repo-tutorial.asimio.net: bs://mavenrepotutorial/release/com/asimio/demo/springboot-togglz-demo/1.0.15/springboot-togglz-demo-1.0.15.jar (31 MB at 1.4 MB/s)
Uploading to maven-repo-tutorial.asimio.net: bs://mavenrepotutorial/release/com/asimio/demo/springboot-togglz-demo/1.0.15/springboot-togglz-demo-1.0.15.pom
Uploaded to maven-repo-tutorial.asimio.net: bs://mavenrepotutorial/release/com/asimio/demo/springboot-togglz-demo/1.0.15/springboot-togglz-demo-1.0.15.pom (5.0 kB at 28 kB/s)
Downloading from maven-repo-tutorial.asimio.net: bs://mavenrepotutorial/release/com/asimio/demo/springboot-togglz-demo/maven-metadata.xml
Uploading to maven-repo-tutorial.asimio.net: bs://mavenrepotutorial/release/com/asimio/demo/springboot-togglz-demo/maven-metadata.xml
Uploaded to maven-repo-tutorial.asimio.net: bs://mavenrepotutorial/release/com/asimio/demo/springboot-togglz-demo/maven-metadata.xml (638 B at 3.9 kB/s)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
...

Deploying a Maven release artifact to an Azure Storage Container Deploying a Maven release artifact to an Azure Storage Container

5. USING DEPLOYED ARTIFACTS

Now that you stored your libraries or custom Spring Boot Starters in an Azure Blob Storage Container, how would you include and use them with Maven in a new or existing application?

You need a few Maven configuration changes.

First, you need to let Maven know about your organization’s public or private repository manager.

For instance, for Maven to find your release libraries you would specify the repository location either in ~/.m2/settings.xml, which is usually the case, or in pom.xml as follow:

<repositories>
  <repository>
    <id>maven-repo-tutorial.asimio.net</id>
    <name>asimiotech-maven-repo-release</name>
    <url>bs://mavenrepotutorial/release</url>
    <snapshots>
      <enabled>false</enabled>
    </snapshots>
    <releases>
      <enabled>true</enabled>
    </releases>
  </repository>
</repositories>

Second, you need the azure-storage-wagon extension in your applications’ pom.xml’s build section:

<build>
  <extensions>
    <extension>
      <groupId>com.gkatzioura.maven.cloud</groupId>
      <artifactId>azure-storage-wagon</artifactId>
      <version>1.8</version>
    </extension>
  </extensions>
...
</build>

And third, you need a server configuration in settings.xml similar to this one with the credentials for Maven to connect to the Azure Storage Container.

Keep in mind that the repository id must match the server id, maven-repo-tutorial.asimio.net in our case.

This is how building an application that uses a dependency stored in a private repository hosted in an Azure Storage Container looks like:

mvn --settings settings.xml clean package -Dazure-storage-user-secret-key=XXXX
...
[INFO] --------------------------------[ jar ]---------------------------------
Downloading from maven-repo-tutorial.asimio.net: bs://mavenrepotutorial/release/com/asimiotech/springboot2-logback-json/1.0.1/springboot2-logback-json-1.0.1.pom
Downloaded from maven-repo-tutorial.asimio.net: bs://mavenrepotutorial/release/com/asimiotech/springboot2-logback-json/1.0.1/springboot2-logback-json-1.0.1.pom (3.2 kB at 2.9 kB/s)
Downloading from maven-repo-tutorial.asimio.net: bs://mavenrepotutorial/release/com/asimiotech/springboot2-logback-json/1.0.1/springboot2-logback-json-1.0.1.jar
Downloaded from maven-repo-tutorial.asimio.net: bs://mavenrepotutorial/release/com/asimiotech/springboot2-logback-json/1.0.1/springboot2-logback-json-1.0.1.jar (20 MB at 8.7 MB/s)
...


6. CONCLUSION

Hosting Java artifacts using Azure Blob Storage would be valid for a solo developer or a small team already invested in Azure. Although a better choice than checking in the resulting artifacts into the SCM, it has some limitations. You won’t be able to Search for an artifact, which is convenient when you need to find out the artifactId, groupId and version of a dependency. Another limitation is maintenance. As the snapshot folder grows overtime, you would have to manually remove older versions.

A solution to these problems could be automated when using a feature-rich Maven repository manager like Nexus or Artifactory but as mentioned in the Overview, it would also require more effort to set it up and a running server or a subscription to a paid plan. Azure Artifacts is another alternative which I might cover in the future.

Thanks for reading and as always, feedback is very much appreciated. If you found this post helpful and would like to receive updates when content like this gets published, sign up to the newsletter.

7. REFERENCES