Cloud customer?
Start for Free >
Upgrade in MyJFrog >
What's New in Cloud >

Search





Overview

The Maven Artifactory Plugin, Artifactory is fully integrated with Maven builds and allows you to do the following:
  1. Attach properties to published artifacts in Artifactory metadata.
  2. Capture a Build Info object which can be passed to the Artifactory REST API to provide a fully traceable build context.
  3. Automatically publish all build artifacts at the end of the build.

Source Code Available!

The Maven Artifactory Plugin is an open-source project on GitHub which you can freely browse and fork.

Page Contents

 


Usage

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

A typical build plugin configuration would be as follows:

<build>
    <plugins>
        ...
        <plugin>
            <groupId>org.jfrog.buildinfo</groupId>
            <artifactId>artifactory-maven-plugin</artifactId>
            <version>3.2.3</version>
            <inherited>false</inherited>
            <executions>
                <execution>
                    <id>build-info</id>
                    <goals>
                        <goal>publish</goal>
                    </goals>
                    <configuration>
                        <deployProperties>
                            <gradle>awesome</gradle>
                            <review.team>qa</review.team>
                        </deployProperties>
                        <publisher>
                            <contextUrl>https://oss.jfrog.org</contextUrl>
                            <username>deployer</username>
                            <password>{DESede}...</password>
                            <repoKey>libs-release-local</repoKey>
                            <snapshotRepoKey>libs-snapshot-local</snapshotRepoKey>
                        </publisher>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

The plugin's invocation phase is validate by default and we recommend you don't change it so the plugin is called as early as possible in the lifecycle of your Maven build.


Configuration

The example above configures the Artifactory publisher,  to deploy build artifacts either to the releases or the snapshots repository of the  public OSS instance of Artifactory when mvn deploy is executed. 

However, the Maven Artifactory Plugin provides many other configurations which you can see by running mvn -X validate and are displayed below:

<deployProperties> .. </deployProperties>
<artifactory>
  <envVarsExcludePatterns> .. </envVarsExcludePatterns>
  <envVarsIncludePatterns> .. </envVarsIncludePatterns>
  <includeEnvVars>true/false</includeEnvVars>
  <timeoutSec>N</timeoutSec>
</artifactory>
<publisher>
  <contextUrl> .. </contextUrl>
  <username> .. </username>
  <password> .. </password>
  <repoKey> .. </repoKey>
  <snapshotRepoKey> .. </snapshotRepoKey>
  <publishArtifacts>true/false</publishArtifacts>
  <publishBuildInfo>true/false</publishBuildInfo>
  <excludePatterns> .. </excludePatterns>
  <includePatterns> .. </includePatterns>
  <filterExcludedArtifactsFromBuild>true/false</filterExcludedArtifactsFromBuild>
  <!-- If true build information published to Artifactory will include implicit project as well as build-time dependencies -->
  <recordAllDependencies>true/false</recordAllDependencies>
  <!-- Minimum file size in KB for which the plugin performs checksum deploy optimization. Default: 10. Set to 0 to disable uploading files with checksum that already exists in Artifactory. -->
  <minChecksumDeploySizeKb>10</minChecksumDeploySizeKb>
 </publisher>
<buildInfo>
  <agentName> .. </agentName>
  <agentVersion> .. </agentVersion>
  <buildName> .. </buildName>
  <buildNumber> .. </buildNumber>
  <buildNumbersNotToDelete> .. </buildNumbersNotToDelete>
  <buildRetentionMaxDays>N</buildRetentionMaxDays>
  <buildRetentionCount>N</buildRetentionCount>
  <buildUrl> .. </buildUrl>
  <principal> .. </principal>
</buildInfo>
<deployProperties>

Specifies properties you can attach to published artifacts. For example:

<deployProperties>
    <groupId>${project.groupId}</groupId>
    <artifactId>${project.artifactId}</artifactId>
    <version>${project.version}</version>
</deployProperties>
<artifactory>
 Specifies whether environment variables are published as part of BuildInfo metadata and which include or exclude patterns are applied when variables are collected
<publisher>

Defines an Artifactory repository where build artifacts should be published using a combination of a <contextUrl> and <repoKey>/<snapshotRepoKey>.

Build artifacts are deployed if the deploy goal is executed and only after all modules are built

<buildInfo>
Updates BuildInfo metadata published together with build artifacts. You can configure whether or not BuildInfo metadata is published using the <publisher> configuration.

Reading 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:

1
2
3
4
5
6
7
8

<publisher>
    <contextUrl>{{ARTIFACTORY_CONTEXT_URL|"https://oss.jfrog.org"}}</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>

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 or 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, null will be used (for example, for expression {{V1|V2}} where neither V1 nor V2 can be resolved).  

Examples

The following project provides a working example of using the plugin:

Maven Artifactory Plugin


Release Notes

 Click here to expand...
3.3.0 (12 Sep 2021)
  1. Populate build-info with VCS information.
3.2.3 (6 Jun 2021)
  1. Update build-info-extractor to 2.26.4.
3.2.1 (16 February 2021)
  1. Plugin is uploaded to Maven Central.
  2. Bugfix - Replaced variables are overridden after a project started.
3.2.0 (18 January 2021)
  1. Allow plugin to be inherited.
  2. Allow configuring the minimal file size for the checksum deploy algorithm.
3.1.0 (14 January 2021)
  1. Reintroduce the expression syntax algorithm of environment and system variables.
3.0.0 (30 September 2020)
  1. Migrate code base from https://github.com/jfrog/build-info to https://github.com/jfrog/artifactory-maven-plugin.
  2. Parallel artifacts deployment using 3 threads.
  3. Build-info - Populate the Build Agent with the plugin name and version.
  4. Breaking changes: <licenses> and <blackDuck> configurations had been removed.
  5. Breaking changes: The expression syntax algorithm of environment and system variables had been removed.
  • No labels
Copyright © 2021 JFrog Ltd.