2 min to read
Build Maven Project with JFrog CLI
JFrog Artifactory is a leading binary repository manager. You can publish artifacts to Artifactory in several ways:
- Using your package manager’s CLI (e.g.,
npm
,nuget
, etc.) - Through the Artifactory Web UI
- Via the REST API
- With the official JFrog CLI (recommended for automation)
The JFrog CLI is a powerful tool that wraps the REST API, making automation and scripting much easier.
📦 What is JFrog CLI?
From the official documentation:
JFrog CLI is a compact and smart client that provides a simple interface to automate access to JFrog products, simplifying your automation scripts and making them more readable and easier to maintain.
🚀 How to Build & Publish a Maven Project Using JFrog CLI
This guide assumes a Unix-based system.
1. Download JFrog CLI
Install JFrog CLI globally or in your project root:
curl -fL https://getcli.jfrog.io | sh
2. Configure JFrog CLI
Set up your Artifactory server connection:
./jfrog rt config <artifactory_server_id> \
--url=<artifactory_url> \
--user=<username> \
--password=<password>
Verify your configuration:
./jfrog rt config show
3. Add a Maven Configuration File
In your Maven project root, create a configuration.yml
file to define your repositories:
version: 1
type: maven
resolver:
snapshotRepo: libs-snapshot
releaseRepo: libs-release
serverID: <artifactory_server_id>
deployer:
snapshotRepo: libs-snapshot-local
releaseRepo: libs-release-local
serverID: <artifactory_server_id>
ℹ️ If you haven’t set up Maven repositories in Artifactory, see the official docs for guidance.
4. Build and Publish Your Artifact
Run your Maven build through JFrog CLI:
./jfrog rt mvn 'clean install' configuration.yml \
--build-name=<build_name> \
--build-number=<build_number>
Publish the build to Artifactory:
./jfrog rt build-publish <build_name> <build_number>
🛠️ Automate with CI
You can script these steps or integrate them into your CI pipeline for full automation.
See a sample Maven project with JFrog CLI integration here: GitHub Example
The sample also demonstrates how to publish build environment details and Git metadata along with your artifacts.
Have questions or want to share your experience? Leave a comment below or connect with me!
Comments