Skip to main content

maven-plugin

Last updated on

The Harness Maven Plugin simplifies Maven project integration with Harness Artifact Registry by automating artifact deployment and dependency management directly from your Maven build lifecycle.

The plugin provides two main capabilities:

  1. Deploy Artifacts: Automatically upload your Maven artifacts (JARs, WARs, POMs, etc.) to Harness Artifact Registry during the Maven build process
  2. Enforce Dependency Resolution: Ensure all Maven dependencies are fetched through your Harness upstream proxy registries, providing centralized control over your project's dependencies

Installation

Add the plugin to your project's pom.xml:

<build>
<plugins>
<plugin>
<groupId>io.harness.maven</groupId>
<artifactId>harness-maven-plugin</artifactId>
<version>1.0.0</version>
<executions>
<execution>
<id>deploy-artifacts</id>
<goals>
<goal>deploy</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

Using SNAPSHOT Versions

If you are using a SNAPSHOT version of the plugin (e.g., 1.0.0-SNAPSHOT), add the snapshot repository to resolve it:

<pluginRepositories>
<pluginRepository>
<id>sonatype-snapshots</id>
<url>https://central.sonatype.com/repository/maven-snapshots/</url>
</pluginRepository>
</pluginRepositories>

Configuration

The plugin uses environment variables for configuration. Set these variables before running Maven commands.

Deployment Configuration

Configure deployment to Harness Artifact Registry:

export DEPLOY_REPO_URL="https://pkg.harness.io/pkg/<ACCOUNT_ID>/<REGISTRY_NAME>/maven"
export DEPLOY_USERNAME="your-username"
export DEPLOY_TOKEN="your-token"

Resolution Configuration (Optional)

To enforce dependency resolution through Harness upstream proxy, configure these variables:

Upstream Proxy Required

The enforce resolution feature requires an upstream proxy registry configured in Harness. Learn how to create an upstream proxy registry.

export RESOLVER_REPO_URL="https://pkg.harness.io/pkg/<ACCOUNT_ID>/<REGISTRY_NAME>/maven"
export RESOLVER_USERNAME="your-username"
export RESOLVER_TOKEN="your-token"

Configuration Reference

Environment VariableDescriptionRequired
DEPLOY_REPO_URLRepository URL for deploymentYes (for deploy)
DEPLOY_USERNAMEUsername for deploymentYes (for deploy)
DEPLOY_TOKENToken/password for deploymentYes (for deploy)
DEPLOY_THREAD_COUNTNumber of threads for parallel deployment (default: CPU cores)No
RESOLVER_REPO_URLRepository URL for dependency resolutionYes (for enforce-resolution)
RESOLVER_USERNAMEUsername for resolutionYes (for enforce-resolution)
RESOLVER_TOKENToken/password for resolutionYes (for enforce-resolution)

Usage

Deploy Artifacts

Deploy your Maven project artifacts to Harness Artifact Registry:

mvn deploy

The plugin will:

  1. Build your project artifacts
  2. Upload artifacts to the configured Harness registry
  3. Use parallel threads for faster deployment (configurable via DEPLOY_THREAD_COUNT)

Configure Deployment Thread Count (Optional)

By default, the plugin uses the number of CPU cores for parallel deployment. You can override this:

export DEPLOY_THREAD_COUNT=4
mvn deploy

Enforce Dependency Resolution

Force all Maven dependencies to resolve from Harness upstream proxy:

mvn harness:enforce-resolution

This ensures all dependencies are fetched through your Harness upstream proxy registry, providing centralized control over your project's dependencies.

Skip Deployment for Specific Modules

If you have modules that should NOT be deployed (e.g., documentation modules, test modules, parent POMs), configure them individually:

<!-- In the module's pom.xml that should be skipped -->
<build>
<plugins>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
</plugins>
</build>

The Harness Maven Plugin automatically respects this configuration and skips those modules during deployment.

Example Workflow

Here's a complete example of using the Harness Maven Plugin in a CI/CD pipeline:

# Set deployment credentials
export DEPLOY_REPO_URL="https://pkg.harness.io/pkg/abc123/my-maven-registry/maven"
export DEPLOY_USERNAME="harness-user"
export DEPLOY_TOKEN="${HARNESS_TOKEN}"

# Set resolution credentials (optional)
export RESOLVER_REPO_URL="https://pkg.harness.io/pkg/abc123/maven-proxy/maven"
export RESOLVER_USERNAME="harness-user"
export RESOLVER_TOKEN="${HARNESS_TOKEN}"

# Configure parallel deployment
export DEPLOY_THREAD_COUNT=8

# Enforce dependency resolution through Harness
mvn harness:enforce-resolution

# Build and deploy artifacts
mvn clean deploy