DEV Community

Heanzy Zabala
Heanzy Zabala

Posted on • Updated on

Using Maven's settings.xml server credentials in Gradle

gradle

Introduction

An essential part of a continuous delivery pipeline is building a project's binary package. A binary package contains all the files, libraries, etc. needed for the software to work. The majority of these files are the dependencies. Dependencies are external libraries often stored and hosted in a public repository.

Normally you can download these dependencies without any form of authentication, you just have to specify the repository, where it's stored, and the dependency itself:

But if you're in an organization that maintains and hosts their libraries then you may have to set your credentials to your organization's repository in your settings.xml using servers:

.. that you can use to download internal dependencies:

Problem

Now, we won't be able to port this exact functionality to Gradle as it doesn't have support for servers or its any of its equivalent, like how pom.xml is synonymous to build.gradle. But of course, it's still possible to achieve the behavior using this:

It's not really a problem, but if you prefer maintaining only one config rather than creating a separate one for Gradle proejcts, then there's a workaround for that.

Solution

I did a bit of googling and came across this Stackoverflow post, which led me to this Gradle issue and ultimately to this Github project. And as the project implies:

Applies security defined for a repository in Maven's settings.xml file to MavenRepository elements in a Gradle build — both upload and download

To implement it, we just have to install and apply the plugin and replace the credentials block with name, which is the id of the server we defined in the settings.xml.

With this, you should be able to publish artifacts to a secured repository as well.

That's all. Cheers!

Top comments (0)