Grade plugin logo

Clarity CodeArtifact Gradle Plugin

David Arques
Clarity AI Tech
2 min readMay 26, 2021

--

Clarity CodeArtifact is a Gradle plugin that manages configuration of Maven repositories with CodeArtifact seamlessly, supports several AWS profiles and provides multiple configuration options.

Why did we build the plugin?

As in many companies, at Clarity we generate dozens of artifacts for internal use each day, so an artifact manager is mandatory. Some time ago we maintained a Nexus repository using Amazon EC2, but we started to have problems due to internal indexes failures that even ended up stopping all pipelines and developments. So, we considered migrating to other solutions, and finally we chose CodeArtifact, mainly because almost all our platform is already hosted on Amazon and no maintenance is needed.

CodeArtifact requires users to authenticate by creating an authorization token using their AWS credentials, which can be a tedious process locally and in the CI environment even more taking into account the usually short token validity period. Most of the Clarity projects use Gradle, so we immediately looked for a plugin that automatically authenticates to CodeArtifact and configures the repository user with the needed token and believe it or not there were none, so we decided to create a CodeArtifact Gradle Plugin ;)

How to use it?

Now, let’s see how to use the plugin to automatically authenticate against AWS CodeArtifact using your local credentials. If you haven’t already, first set up your AWS credentials.

Just add the following in your build.gradle:

How to use the plugin

Setting the AWS Profile

If you need to authenticate to AWS with a different profile than the default, there are four options:

1. Define the environment variable AWS_PROFILE with the profile name you want to use.

Note: This plugin uses AWS SDK for authorization, all the standard environment variables are applicable.

2. Define the environment variable CODEARTIFACT_PROFILE with the profile name you want to use. If you need a different profile for CodeArtifact than for the rest of AWS calls you can use this environment var.

3. Define the profile using a system property. If you need a different profile for CodeArtifact and you cannot define an environment variable, you can define it via system property as well:

  • This way using gradle.properties file:
systemProp.codeartifact.profile=<your profile>
  • Or using the command line:
gradle -Dcodeartifact.profile=<your profile> …

4. Add the profile name to the repository URL as a query parameter:

Setting AWS profile through URL

Note: The query parameter is used to configure the profile and automatically removed from the URL in any request to AWS.

Collaborations

Clarity CodeArtifact Gradle plugin is an open-source project under Apache License 2.0. So don’t hesitate to contribute, any feedback or PR are more than welcome.

References:

Thanks to all Clarity AI Engineering Team who have participated in this project and article, especially to Joan Fisbein, Jerónimo López and Jmiguel Rodriguez.

--

--