Search results
Using Azure Blob Storage as your Maven Repository
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.
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
- Then continue creating a 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.
Account Containers
- Click on the
+ Container
button to create thesnapshot
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
You could add these server
settings in your existing ~/.m2/settings.xml
or in a new file as done in this tutorial.
password
to have the User secret key, please make sure this file is protected and/or the password is encrypted.
Alternatively, you could pass it via VM argument -Dazure-storage-user-secret-key=XXXX
.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
Let’s now configure the artifact’s pom.xml
:
pom.xml
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
Deploying a Maven snapshot artifact to an Azure Storage Container
4.2. DEPLOYING A RELEASE
This command updates the version of the artifact.
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.