Skip to main content

maven-quickstart

This guide will help you create a Maven Artifact Registry in Harness, configure an upstream proxy, and manage Maven packages.

Prerequisites

  • Ensure you have the Maven CLI (mvn) installed on your local machine.
  • Access to a Harness account with appropriate permissions to create registries and connectors.

Create a Maven Artifact Registry

private registry

This registry will serve as your private Maven registry within Harness.


Configure an Upstream Proxy (Optional)

An upstream proxy allows your registry to fetch Maven packages from external sources if they are not available locally.

Create an upstream proxy

Configure the upstream proxy in your registry

upstream proxy caching

If a Maven package isn’t found in your Harness registry, the upstream proxy fetches it from an external registry like Maven Central, reducing duplication and improving resolution.


Push & Pull Maven Packages

Authenticate the CLI with the Harness Registry

  1. In your Harness Maven Artifact Registry, click Setup Client.
  2. Click Generate Identity Token to generate a new token that serves as the password for uploading and downloading artifacts.

Publish a Package to the Registry

  1. Set default repository in your pom.xml file.
<distributionManagement>
<snapshotRepository>
<id>maven-dev</id>
<url>https://pkg.harness.io/pkg/<account-id>/<maven-registry>/maven</url>
</snapshotRepository>
<repository>
<id>maven-dev</id>
<url>https://pkg.harness.io/pkg/<account-id>/<maven-registry>/maven</url>
</repository>
</distributionManagement>
  1. Copy the following your ~/ .m2/setting.xml file for MacOs, or USERPROFILEUSERPROFILE\ .m2\settings.xml for Windows to authenticate with token to push to your Maven registry.
<settings>
<servers>
<server>
<id>maven-dev</id>
<username>username</username>
<password>identity-token</password>
</server>
</servers>
</settings>
  1. Publish the package:
mvn deploy

Pull a Package from the Registry

Set default repository in your pom.xml file.

  1. Set the default registry in your pom.xml file by adding the following:
<repositories>
<repository>
<id>maven-dev</id>
<url>https://pkg.harness.io/pkg/<account-id>/<maven-registry>/maven</url>
<releases>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</snapshots>
</repository>
</repositories>
  1. Copy the following your ~/ .m2/settings.xml file for MacOs, or USERPROFILEUSERPROFILE\ .m2\settings.xml for Windows to authenticate with token to pull from your Maven registry.
<settings>
<servers>
<server>
<id>maven-dev</id>
<username>username</username>
<password>identity-token</password>
</server>
</servers>
</settings>
  1. Add a dependency to the project's pom.xml (replace GROUP_ID, ARTIFACT_ID & VERSION with your own):
<dependency>
<groupId><GROUP_ID></groupId>
<artifactId><ARTIFACT_ID></artifactId>
<version><VERSION></version>
</dependency>
  1. Pull the package:
mvn install
usage

These commands upload or retrieve Maven packages between your local project and the Harness registry.


By following this guide, you can effectively set up and manage a Maven Artifact Registry within Harness, streamlining your Java package workflows.