Maven Artifactory Plugin

The Maven Artifactory Plugin integrates in your build to allow you to do the following:

  • Resolve artifacts from Artifactory.
  • Capture the full build information and publish it to Artifactory.
  • Deploy all build artifacts to Artifactory.

The Maven Artifactory Plugin coordinates are org.jfrog.buildinfo:artifactory-maven-plugin:x.x.x. It can be viewed on releases.jfrog.io.

Prerequisites

Before using the plugin, ensure your environment meets the following requirements:

  • Maven 3.8.1 or later
  • Java 8 or later (JDK 1.8+)
  • A running JFrog Artifactory instance (SaaS or self-managed) with at least one local repository configured

Getting Started

Add the plugin to the <build> section of your project's pom.xml:

<build>
  <plugins>
    <plugin>
      <groupId>org.jfrog.buildinfo</groupId>
      <artifactId>artifactory-maven-plugin</artifactId>
      <version>3.7.1</version>
      <executions>
        <execution>
          <id>build-info</id>
          <goals>
            <goal>publish</goal>
          </goals>
          <configuration>
            <deployProperties>
              <maven>awesome</maven>
              <review.team>qa</review.team>
            </deployProperties>
            <publisher>
              <contextUrl>https://acme.jfrog.io</contextUrl>
              <username>deployer</username>
              <password>dontellanyone</password>
              <repoKey>libs-release-local</repoKey>
              <snapshotRepoKey>libs-snapshot-local</snapshotRepoKey>
            </publisher>
          </configuration>
        </execution>
      </executions>
    </plugin>
  </plugins>
</build>

Then run:

mvn deploy

This deploys your build artifacts to the configured Artifactory repository and publishes the build information.

Tip: You can use environment variables and system properties instead of hardcoding credentials. For more information, see Using Environment Variables and System Properties.

How It Works

The plugin binds its publish goal to the validate phase by default -- the earliest phase in the Maven lifecycle. Don't change the default phase so the plugin is called as early as possible in the lifecycle of your Maven build.

During validate, the plugin:

  1. Replaces any {{ }} variable expressions in the configuration with their resolved values.
  2. Sets up proxy settings (from the plugin config or your Maven settings.xml).
  3. Replaces the default Maven deploy behavior with its own build-information-aware deployer.

When mvn deploy finishes and all modules are built, the plugin:

  1. Deploys artifacts to the configured Artifactory <publisher> repository.
  2. Publishes the collected build information to Artifactory.

Because the plugin intercepts Maven's deploy lifecycle, you configure a <goal>publish</goal> in the plugin but trigger it by running mvn deploy.

Configuration Reference

The plugin supports the following configuration blocks inside <configuration>. Each is described in the following sections with its parameters.

Publisher

Defines an Artifactory repository where build artifacts should be published. Build artifacts are deployed if the deploy goal is executed and only after all modules are built.

<publisher>
  <contextUrl>http://localhost:8081/artifactory</contextUrl>
  <username>${username}</username>
  <password>${password}</password>
  <repoKey>libs-release-local</repoKey>
  <snapshotRepoKey>libs-snapshot-local</snapshotRepoKey>
  <excludePatterns>*-tests.jar</excludePatterns>
  <includePatterns>..</includePatterns>
  <publishArtifacts>true/false</publishArtifacts>
  <publishBuildInfo>true/false</publishBuildInfo>
  <filterExcludedArtifactsFromBuild>true/false</filterExcludedArtifactsFromBuild>
  <recordAllDependencies>true/false</recordAllDependencies>
  <minChecksumDeploySizeKb>10</minChecksumDeploySizeKb>
</publisher>

The following table describes the publisher parameters.

ParameterDescription
contextUrlThe base URL of the Artifactory instance (for example, https://acme.jfrog.io).
usernameArtifactory username for deployment.
passwordArtifactory password or API key.
repoKeyTarget repository for release artifacts.
snapshotRepoKeyTarget repository for snapshot artifacts. If the deployed artifact version contains -SNAPSHOT, this repository is used instead of repoKey.
excludePatternsComma-separated Ant-style patterns. Matching artifacts are excluded from deployment.
includePatternsComma-separated Ant-style patterns. Only matching artifacts are deployed.
publishArtifactsIf false, artifacts are not deployed. Default: true.
publishBuildInfoIf false, build information is not published. Default: true.
filterExcludedArtifactsFromBuildIf true, artifacts excluded by patterns are also removed from the build information. Default: false.
recordAllDependenciesIf true, build information published to Artifactory will include implicit project as well as build-time dependencies. Default: false.
minChecksumDeploySizeKbMinimum file size in KB for which the plugin performs checksum deploy optimization. Set to 0 to disable uploading files with a checksum that already exists in Artifactory. Default: 10.

Resolver

Defines an Artifactory repository from which build dependencies should be resolved.

<resolver>
  <contextUrl>http://localhost:8081/artifactory</contextUrl>
  <username>${username}</username>
  <password>${password}</password>
  <repoKey>libs-release</repoKey>
  <downloadSnapshotRepoKey>libs-snapshot</downloadSnapshotRepoKey>
</resolver>

The following table describes the resolver parameters.

ParameterDescription
contextUrlThe base URL of the Artifactory instance used for resolution.
usernameArtifactory username for resolution.
passwordArtifactory password or API key.
repoKeyRepository from which release dependencies are resolved.
downloadSnapshotRepoKeyRepository from which snapshot dependencies are resolved.

Build Information

Updates build information metadata published together with build artifacts. You can configure whether or not build information metadata is published using the <publishBuildInfo> flag in the <publisher> section.

<buildInfo>
  <buildName>plugin-demo</buildName>
  <buildNumber>${buildnumber}</buildNumber>
  <buildUrl>https://build-url.org</buildUrl>
  <project>..</project>
  <agentName>..</agentName>
  <agentVersion>..</agentVersion>
  <principal>..</principal>
  <buildRetentionMaxDays>N</buildRetentionMaxDays>
  <buildRetentionCount>N</buildRetentionCount>
  <buildNumbersNotToDelete></buildNumbersNotToDelete>
</buildInfo>

The following table describes the build information parameters.

ParameterDescription
buildNameCustom build name. Defaults to the Maven project's artifactId if not set.
buildNumberCustom build number. Defaults to the build timestamp if not set.
buildUrlURL linking back to the CI build (for example, Jenkins build URL).
projectJFrog Project key to associate the published build-info with.
agentNameName of the CI agent. Defaults to artifactory-maven-plugin.
agentVersionVersion of the CI agent. Defaults to the plugin version.
principalThe user or entity that triggered the build.
buildRetentionMaxDaysMaximum number of days to retain builds in Artifactory.
buildRetentionCountMaximum number of builds to retain.
buildNumbersNotToDeleteComma-separated list of build numbers that should never be deleted by retention policies.

Environment Collection (<artifactory>)

Controls whether environment variables are captured as part of build information metadata and which include or exclude patterns are applied when variables are collected.

The XML element is <artifactory>, not to be confused with the Artifactory server itself.

<artifactory>
  <includeEnvVars>true</includeEnvVars>
  <envVarsExcludePatterns>*password*,*secret*,*key*,*token*,*passphrase*</envVarsExcludePatterns>
  <envVarsIncludePatterns>*os*</envVarsIncludePatterns>
  <timeoutSec>60</timeoutSec>
</artifactory>

The following table describes the environment collection parameters.

ParameterDescription
includeEnvVarsIf true, environment variables are collected into build information. Default: true.
envVarsExcludePatternsComma-separated wildcard patterns. Matching environment variables are excluded from collection. Default: *password*,*secret*,*key*,*token*,*passphrase*.
envVarsIncludePatternsComma-separated wildcard patterns. Only matching environment variables are collected.
timeoutSecConnection timeout in seconds for Artifactory operations. Default: 60.

Deploy Properties

Specifies custom properties to attach to every deployed artifact. Each child element becomes a key=value property.

<deployProperties>
  <maven>awesome</maven>
  <review.team>qa</review.team>
</deployProperties>

In this example, every artifact deployed to Artifactory will have the properties maven=awesome and review.team=qa attached.

Proxy

Specifies an HTTP/S proxy for connecting to Artifactory. If no <host> is provided in the plugin configuration, the plugin falls back to the active proxy defined in your Maven settings.xml.

<proxy>
  <host>proxy.jfrog.io</host>
  <port>8888</port>
  <username>proxyUser</username>
  <password>proxyPassword</password>
</proxy>

The following table describes the proxy parameters.

ParameterDescription
hostProxy hostname.
portProxy port.
usernameProxy authentication username.
passwordProxy authentication password.

Full Configuration Example

The following shows all configuration blocks combined for reference. You can copy this as a starting point and remove sections you don't need.

<configuration>
  <artifactory>
    <includeEnvVars>true</includeEnvVars>
    <envVarsExcludePatterns>*password*,*secret*,*key*,*token*,*passphrase*</envVarsExcludePatterns>
    <envVarsIncludePatterns>*os*</envVarsIncludePatterns>
    <timeoutSec>60</timeoutSec>
  </artifactory>
  <buildInfo>
    <agentName>..</agentName>
    <agentVersion>..</agentVersion>
    <buildName>plugin-demo</buildName>
    <buildNumber>${buildnumber}</buildNumber>
    <buildUrl>https://build-url.org</buildUrl>
    <project>..</project>
    <buildNumbersNotToDelete></buildNumbersNotToDelete>
    <buildRetentionMaxDays>N</buildRetentionMaxDays>
    <buildRetentionCount>N</buildRetentionCount>
    <principal>..</principal>
  </buildInfo>
  <deployProperties>
    <maven>awesome</maven>
  </deployProperties>
  <publisher>
    <contextUrl>http://localhost:8081/artifactory</contextUrl>
    <username>${username}</username>
    <password>${password}</password>
    <repoKey>libs-release-local</repoKey>
    <snapshotRepoKey>libs-snapshot-local</snapshotRepoKey>
    <excludePatterns>*-tests.jar</excludePatterns>
    <includePatterns>..</includePatterns>
    <publishArtifacts>true/false</publishArtifacts>
    <publishBuildInfo>true/false</publishBuildInfo>
    <filterExcludedArtifactsFromBuild>true/false</filterExcludedArtifactsFromBuild>
    <recordAllDependencies>true/false</recordAllDependencies>
    <minChecksumDeploySizeKb>10</minChecksumDeploySizeKb>
  </publisher>
  <resolver>
    <contextUrl>http://localhost:8081/artifactory</contextUrl>
    <username>${username}</username>
    <password>${password}</password>
    <repoKey>libs-release</repoKey>
    <downloadSnapshotRepoKey>libs-snapshot</downloadSnapshotRepoKey>
  </resolver>
  <proxy>
    <host>proxy.jfrog.io</host>
    <port>8888</port>
    <username>proxyUser</username>
    <password>proxyPassword</password>
  </proxy>
</configuration>

Using Environment Variables and System Properties

Every build server provides its own set of environment variables. You can utilize these variables when configuring the plugin as shown in the following example:

<configuration>
  <publisher>
    <contextUrl>{{ARTIFACTORY_CONTEXT_URL|"https://acme.jfrog.io"}}</contextUrl>
  </publisher>
  <buildInfo>
    <buildNumber>{{DRONE_BUILD_NUMBER|TRAVIS_BUILD_NUMBER|CI_BUILD_NUMBER|BUILD_NUMBER|"333"}}</buildNumber>
    <buildUrl>{{DRONE_BUILD_URL|CI_BUILD_URL|BUILD_URL}}</buildUrl>
  </buildInfo>
</configuration>

Any plugin configuration value can contain several {{ .. }} expressions. Each expression can contain a single or multiple environment variables or system properties to be used. The expression syntax allows you to provide enough variables to accommodate any build server requirements according to the following rules:

  • Each expression can contain several variables, separated by a | character to be used with a configuration value.
  • The last value in a list is the default that will be used if none of the previous variables is available as an environment variable or a system property.
  • For example, for the expression {{V1|V2|"defaultValue"}} the plugin will attempt to locate environment variable V1, then system property V1, then environment variable V2, then system property V2, and if none of these is available, "defaultValue" will be used.
  • If the last value is not a string (as denoted by the quotation marks) and the variable cannot be resolved, an empty string will be used (for example, for expression {{V1|V2}} where neither V1 nor V2 can be resolved).

Example Project

The following project provides a working example of using the plugin: Maven Artifactory Plugin Example.

Contributions

Pull requests from the community are welcome. For more information, see the Contribution guide.