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 deployThis 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:
- Replaces any
{{ }}variable expressions in the configuration with their resolved values. - Sets up proxy settings (from the plugin config or your Maven
settings.xml). - Replaces the default Maven deploy behavior with its own build-information-aware deployer.
When mvn deploy finishes and all modules are built, the plugin:
- Deploys artifacts to the configured Artifactory
<publisher>repository. - 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.
| Parameter | Description |
|---|---|
contextUrl | The base URL of the Artifactory instance (for example, https://acme.jfrog.io). |
username | Artifactory username for deployment. |
password | Artifactory password or API key. |
repoKey | Target repository for release artifacts. |
snapshotRepoKey | Target repository for snapshot artifacts. If the deployed artifact version contains -SNAPSHOT, this repository is used instead of repoKey. |
excludePatterns | Comma-separated Ant-style patterns. Matching artifacts are excluded from deployment. |
includePatterns | Comma-separated Ant-style patterns. Only matching artifacts are deployed. |
publishArtifacts | If false, artifacts are not deployed. Default: true. |
publishBuildInfo | If false, build information is not published. Default: true. |
filterExcludedArtifactsFromBuild | If true, artifacts excluded by patterns are also removed from the build information. Default: false. |
recordAllDependencies | If true, build information published to Artifactory will include implicit project as well as build-time dependencies. Default: false. |
minChecksumDeploySizeKb | Minimum 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.
| Parameter | Description |
|---|---|
contextUrl | The base URL of the Artifactory instance used for resolution. |
username | Artifactory username for resolution. |
password | Artifactory password or API key. |
repoKey | Repository from which release dependencies are resolved. |
downloadSnapshotRepoKey | Repository 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.
| Parameter | Description |
|---|---|
buildName | Custom build name. Defaults to the Maven project's artifactId if not set. |
buildNumber | Custom build number. Defaults to the build timestamp if not set. |
buildUrl | URL linking back to the CI build (for example, Jenkins build URL). |
project | JFrog Project key to associate the published build-info with. |
agentName | Name of the CI agent. Defaults to artifactory-maven-plugin. |
agentVersion | Version of the CI agent. Defaults to the plugin version. |
principal | The user or entity that triggered the build. |
buildRetentionMaxDays | Maximum number of days to retain builds in Artifactory. |
buildRetentionCount | Maximum number of builds to retain. |
buildNumbersNotToDelete | Comma-separated list of build numbers that should never be deleted by retention policies. |
Environment Collection (<artifactory>)
<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.
| Parameter | Description |
|---|---|
includeEnvVars | If true, environment variables are collected into build information. Default: true. |
envVarsExcludePatterns | Comma-separated wildcard patterns. Matching environment variables are excluded from collection. Default: *password*,*secret*,*key*,*token*,*passphrase*. |
envVarsIncludePatterns | Comma-separated wildcard patterns. Only matching environment variables are collected. |
timeoutSec | Connection 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.
| Parameter | Description |
|---|---|
host | Proxy hostname. |
port | Proxy port. |
username | Proxy authentication username. |
password | Proxy 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 variableV1, then system propertyV1, then environment variableV2, then system propertyV2, 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 neitherV1norV2can 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.
Updated 1 day ago
