MYHOSPITALNOW.COM

Find Trusted Doctors & Hospitals

Discover healthcare providers, compare hospitals, and explore treatment options worldwide.

Free Treatment Quotes • Doctor Search • Hospital Comparison

Find Healthcare Options

www.myhospitalnow.com

Artifactory: using Gradle and Uploading Artifacts to Artifactory

Step-by-Step Guide: Creating a Java Project with Gradle and Uploading Artifacts to Artifactory

1. Install Prerequisites

  • Java JDK: Ensure Java (preferably JDK 17 or newer) is installed. Check with java -version.
  • Gradle: Install Gradle (version 8+ recommended). Check with gradle -version.

2. Create a New Java Project Using Gradle

Open your terminal and execute:

textgradle init --type java-application
  • Follow the interactive prompts to choose Java as the language and select other defaults as needed.
  • This command will generate a new Gradle Java project with a standard directory structure1234.

Alternatively, you can manually create a folder, navigate into it, and execute gradle init to set up your project.

3. Build the Project

Navigate into your project folder (if not already there):

textcd your-project-name

Build and test your project:

textgradle build

Youโ€™ll find the generated JAR in build/libs folder.

4. Add Artifactory Publishing Support

a. Apply the Artifactory Plugin

Add the following to your build.gradle (Groovy DSL):

groovyplugins {
    id 'java'
    id 'maven-publish'
    id 'com.jfrog.artifactory' version '5.2.0' // Use the latest compatible version
}

b. Configure Artifactory Publishing

Add this to your build.gradle:

groovypublishing {
    publications {
        mavenJava(MavenPublication) {
            from components.java
        }
    }
}

artifactory {
    contextUrl = 'https://artifactory.example.com/artifactory' // <-- your Artifactory URL
    publish {
        repository {
            repoKey = 'libs-release-local' // or your repository key
            username = findProperty('artifactory_user') ?: System.getenv('ARTIFACTORY_USER')
            password = findProperty('artifactory_password') ?: System.getenv('ARTIFACTORY_PASSWORD')
            maven = true
        }
        defaults {
            publications('mavenJava')
        }
    }
}

Important: Never hardcode credentials. Use Gradle properties files (~/.gradle/gradle.properties) or environment variables to provide artifactory_user and artifactory_password56.

c. Optional: Add Snapshots Repo

If you need to deploy snapshot versions, add a similar block for a snapshot repository with the appropriate repoKey.

5. Publish to Artifactory

Deploy your artifact to Artifactory by running:

textgradle artifactoryPublish

If everything is set up correctly, your artifact will be uploaded to the specified location in Artifactory76.

Summary Table

StepCommand/Action
New Gradle Projectgradle init --type java-application
Build Projectgradle build
Add Artifactory PluginEdit build.gradle
Configure PublishingEdit build.gradle/set credentials
Deploy Artifactgradle artifactoryPublish

With these steps, you can create a new Java Gradle project and publish its build artifacts directly to your Artifactory server in a secure and repeatable manner1756.

Another Method

Here is a step-by-step guide to create a new Java project using Gradle and configure it to upload artifacts to JFrog Artifactory.


โœ… 1๏ธโƒฃ Install Prerequisites

  • Java JDK (version 8+)
  • Gradle (latest version recommended)
  • Artifactory URL & credentials (from your DevOps/admin team)

Verify installation:

java -version
gradle -v

โœ… 2๏ธโƒฃ Create a New Gradle Java Project

Option A: Using Gradle CLI

gradle init --type java-application

Follow prompts:

  • Project type: application
  • Language: Java
  • Build script DSL: Groovy or Kotlin

This will create:

build.gradle
settings.gradle
src/main/java
src/test/java

โœ… 3๏ธโƒฃ Configure build.gradle for Publishing

Open build.gradle and make the following changes:

๐Ÿ”น Apply Required Plugins

plugins {
    id 'java'
    id 'maven-publish'
}
Code language: JavaScript (javascript)

๐Ÿ”น Configure Group, Version & Artifact Name

group = 'com.example'
version = '1.0.0'
Code language: JavaScript (javascript)

๐Ÿ”น Setup Artifactory Publishing

Add this to build.gradle:

publishing {
    publications {
        mavenJava(MavenPublication) {
            from components.java
            groupId = 'com.example'
            artifactId = 'my-artifact'
            version = '1.0.0'
        }
    }

    repositories {
        maven {
            url = uri("https://your-artifactory-domain/artifactory/libs-release-local")
            credentials {
                username = project.findProperty("artifactory_user") ?: "your-username"
                password = project.findProperty("artifactory_password") ?: "your-password"
            }
        }
    }
}
Code language: JavaScript (javascript)

โœ… 4๏ธโƒฃ Store Credentials Securely

Instead of hardcoding, use gradle.properties:

๐Ÿ“‚ ~/.gradle/gradle.properties

artifactory_user=admin
artifactory_password=your-api-key-or-password

โœ… 5๏ธโƒฃ Build the Artifact

Run:

gradle clean build

Output: JAR file inside build/libs/my-artifact-1.0.0.jar.


โœ… 6๏ธโƒฃ Publish to Artifactory

Run:

gradle publish

โœ… This uploads the JAR to your Artifactory repository.


โœ… 7๏ธโƒฃ Verify Upload

  • Open Artifactory web UI
  • Navigate to your repository (libs-release-local)
  • Confirm my-artifact-1.0.0.jar is uploaded.

โœ… 8๏ธโƒฃ (Optional) Use the JFrog Gradle Plugin

JFrog provides a dedicated plugin for advanced features like build-info and CI/CD integration.

Add to build.gradle:

plugins {
    id "com.jfrog.artifactory" version "5.2.0"
}
Code language: JavaScript (javascript)

Configure:

artifactory {
    contextUrl = "https://your-artifactory-domain/artifactory"
    publish {
        repository {
            repoKey = "libs-release-local"
            username = "${artifactory_user}"
            password = "${artifactory_password}"
        }
        defaults {
            publications('mavenJava')
        }
    }
}
Code language: JavaScript (javascript)

Publish:

gradle artifactoryPublish

๐Ÿ“Œ Summary

โœ… You created a Java project using Gradle
โœ… Configured it to upload artifacts to JFrog Artifactory
โœ… Secured credentials with gradle.properties
โœ… Used gradle publish to push JAR to Artifactory


Find Trusted Cardiac Hospitals

Compare heart hospitals by city and services โ€” all in one place.

Explore Hospitals
I'm Rajesh Kumar, a DevOps, SRE, DevSecOps, Cloud, and Platform Engineering expert passionate about sharing practical knowledge, real-world experiences, and industry best practices. I have worked at Cotocus and regularly write about technology, travel, investing, health, product reviews, and digital marketing through my various platforms. I publish technical articles at DevOps School, travel stories at Holiday Landmark, stock market insights at Stocks Mantra, health and fitness guidance at My Medic Plus, product reviews at TrueReviewNow, and SEO and digital marketing strategies at Wizbrand.

Related Posts

Develocity: The Complete Beginner-to-Advanced Tutorial

A practical self-study course covering Developer Productivity Engineering, Build Scan, Build Cache, build acceleration, test optimization, architecture, deployment, integrations, security, and enterprise operations. 28 chapters | Beginner…

Read More

Gradle Training Curriculum: Hands-On Learning Path for Build and DevOps Engineers

A revised, practical Gradle training guide based on the original course outline. It maps the agenda to hands-on labs, CI workflow, and team-ready build practices.

Read More

Sonatype Nexus Repository Manager: A Practical DevOps Introduction

Sonatype Nexus helps teams centralize dependency downloads and internal artifact publishing. This guide shows how Nexus fits into CI/CD, when to use hosted/proxy/group repos, and how to configure common build clients.

Read More

Gradle for DevOps: Core Concepts, Build Workflow, and Practical Examples

Gradle is a flexible build automation tool used to compile, test, package, and publish software in repeatable pipelines. This guide explains how Gradle works, how it compares with Maven and Ant, and how to start with practical commands.

Read More

Advanced Features of Smart Build Tools for Faster, Reproducible CI/CD

Smart build tools do much more than compile code: they cache, parallelize, enforce dependency rules, and improve reproducibility. This guide compares common options and shows practical commands you can use in real pipelines.

Read More

Senior DevOps Tooling Administrator: Role Blueprint, Responsibilities, Skills, KPIs, and Career Path

The **Senior DevOps Tooling Administrator** is accountable for the reliability, security, lifecycle management, and user experience of the organizationโ€™s **developer productivity and delivery tooling** (CI/CD, source control administration, artifact management, secrets, runners/agents, integrations, and related platform services). This role ensures these tools are **available, compliant, performant, cost-effective, and well-governed**, enabling engineering teams to ship software safely and quickly.

Read More
Subscribe
Notify of
guest
1 Comment
Newest
Oldest Most Voted
Jason Mitchell
Jason Mitchell
8 months ago

Thanks for this clear guide on using Gradle with Artifactory! ๐Ÿ“ฆ The steps and explanations make it much easier to understand how to upload artifacts and manage builds. Very helpful for developers learning CI/CD workflows. Appreciate you sharing this!

1
0
Would love your thoughts, please comment.x
()
x