Host Your Maven Artifacts Using Azure Blob Storage
Want to use Azure Blob Storage to host your Maven artifacts? Here's a simple guide to bringing your Java projects to the cloud for ease of accessibility.
Join the DZone community and get the full member experience.
Join For FreeIf you use Microsoft Azure and you use Java for your projects, then Azure Blob Storage is a great place to host your team's artifacts.
It is easy to set up and pretty cheap. Also, it is much simpler than setting one of the existing repository options (JFrog, Nexus, Archiva, etc.) if you are not particularly interested in their features.
To get started, you need to specify a Maven wagon that supports Azure Blob Storage.
We will use the Azure storage wagon.
Let’s get started by creating a maven project:
mvn archetype:generate -DgroupId=com.test.apps -DartifactId=AzureWagonTest -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false
We are going to add a simple service.
package com.test.apps;
public class HelloService {
public String sayHello() {
return "Hello";
}
}
Then we are going to add the Maven wagon, which will upload and fetch our binaries to Azure Blob Storage.
<build>
<extensions>
<extension>
<groupId>com.gkatzioura.maven.cloud</groupId>
<artifactId>azure-storage-wagon</artifactId>
<version>1.0</version>
</extension>
</extensions>
</build>
Then we shall create the Azure storage account that will host our artifacts.
Then we shall create a new container called snapshot. This container will contain our snapshot repositories.
We can go through the same process in order to create a release repository. Be aware that there is no need to create different containers for each repository. You can have repositories under the same container.
Now that we have set up our storage account in Azure, we shall set the distribution management on our Maven project.
<distributionManagement>
<snapshotRepository>
<id>my-repo-bucket-snapshot</id>
<url>bs://mavenrepository/snapshot</url>
</snapshotRepository>
<repository>
<id>my-repo-bucket-release</id>
<url>bs://mavenrepository/release</url>
</repository>
</distributionManagement>
From the Maven documentation:
Where as the repositories element specifies in the POM the location and manner in which Maven may download remote artifacts for use by the current project, distributionManagement specifies where (and how) this project will get to a remote repository when it is deployed. The repository elements will be used for snapshot distribution if the snapshotRepository is not defined.
The next step is the most crucial, and this has to to do with authenticating to Azure.
What you need is your storage account name and the key of the storage account. In order to retrieve both, you have to navigate to the Access keys of your Storage Account at the Settings section.
Then we shall specify our storage account credentials on ~/.m2/settings.xml:
<servers>
<server>
<id>my-repo-bucket-snapshot</id>
<username>mavenrepository</username>
<password>eXampLEkeyEMI/K7EXAMP/bPxRfiCYEXAMPLEKEY</password>
</server>
<server>
<id>my-repo-bucket-release</id>
<username>mavenrepository</username>
<password>eXampLEkeyEMI/K7EXAMP/bPxRfiCYEXAMPLEKEY</password>
</server>
</servers>
Be aware that you have to specify credentials for each repository specified.
And now the easiest part, which is deploying:
mvn deploy
Now since your artifact has been deployed, you can use it in another repo by specifying your repository and your wagon.
<repositories>
<repository>
<id>my-repo-bucket-snapshot</id>
<url>bs://mavenrepository/snapshot</url>
</repository>
<repository>
<id>my-repo-bucket-release</id>
<url>bs://mavenrepository/release</url>
</repository>
</repositories>
<build>
<extensions>
<extension>
<groupId>com.gkatzioura.maven.cloud</groupId>
<artifactId>azure-storage-wagon</artifactId>
<version>1.0</version>
</extension>
</extensions>
</build>
That’s it! Next thing you know, your artifact will be downloaded by Maven through Azure Blob Storage and used as a dependency in your new project.
Published at DZone with permission of Emmanouil Gkatziouras, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.
Comments