Find the Best Cosmetic Hospitals

Explore trusted cosmetic hospitals and make a confident choice for your transformation.

โ€œInvest in yourself โ€” your confidence is always worth it.โ€

Explore Cosmetic Hospitals

Start your journey today โ€” compare options in one place.

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 a DevOps/SRE/DevSecOps/Cloud Expert passionate about sharing knowledge and experiences. I have worked at <a href="https://www.cotocus.com/">Cotocus</a>. I share tech blog at <a href="https://www.devopsschool.com/">DevOps School</a>, travel stories at <a href="https://www.holidaylandmark.com/">Holiday Landmark</a>, stock market tips at <a href="https://www.stocksmantra.in/">Stocks Mantra</a>, health and fitness guidance at <a href="https://www.mymedicplus.com/">My Medic Plus</a>, product reviews at <a href="https://www.truereviewnow.com/">TrueReviewNow</a> , and SEO strategies at <a href="https://www.wizbrand.com/">Wizbrand.</a> Do you want to learn <a href="https://www.quantumuting.com/">Quantum Computing</a>? <strong>Please find my social handles as below;</strong> <a href="https://www.rajeshkumar.xyz/">Rajesh Kumar Personal Website</a> <a href="https://www.youtube.com/TheDevOpsSchool">Rajesh Kumar at YOUTUBE</a> <a href="https://www.instagram.com/rajeshkumarin">Rajesh Kumar at INSTAGRAM</a> <a href="https://x.com/RajeshKumarIn">Rajesh Kumar at X</a> <a href="https://www.facebook.com/RajeshKumarLog">Rajesh Kumar at FACEBOOK</a> <a href="https://www.linkedin.com/in/rajeshkumarin/">Rajesh Kumar at LINKEDIN</a> <a href="https://www.wizbrand.com/rajeshkumar">Rajesh Kumar at WIZBRAND</a> <a href="https://www.rajeshkumar.xyz/dailylogs">Rajesh Kumar DailyLogs</a>

Related Posts

Artifactory: Comprehensive Troubleshooting Guide for JFrog Artifactory

Hereโ€™s a very comprehensive, up-to-date troubleshooting guide for JFrog Artifactory 7.x, covering the application, database, core components, all services, log files, and all the key troubleshooting commands.This…

Read More

Artifactory: Setting up Artifactory 7 High Availability Cluster

Here is a comprehensive, step-by-step guide to design, configure, and deploy JFrog Artifactory 7.x in High Availability (HA) modeโ€”including all architectural and configuration considerations required for a…

Read More

Artifactory: Guide to change Artifactory filestore to AWS EFS (Elastic File System)

Hereโ€™s a comprehensive, step-by-step tutorial for migrating or configuring JFrog Artifactory 7.117.7+ (self-hosted, Linux) to use AWS EFS (Elastic File System) as its filestore. This guide brings…

Read More

Artifacatory: Upload Artifacts to Artifactory using NPM with Node.js Project

Step-by-Step Guide: Create a Node.js Project with npm and Upload Artifacts to Artifactory 1. Install Prerequisites 2. Initialize a New Node.js Project 3. Develop Your Node.js Artifact…

Read More

Jfrog Artifactory: Install Artifactory 7 with Postgresql

Hereโ€™s a clear, step-by-step command guide to install the latest JFrog Artifactory (7.117.7) on a Linux server with PostgreSQL as the external database. This walkthrough assumes Ubuntu/Debian,…

Read More

Package Types Supported by Artifactory

Here is a short summary of each of the mentioned package types: Complete List of Package Types Supported by JFrog Artifactory JFrog Artifactory is recognized for its…

Read More
Subscribe
Notify of
guest
1 Comment
Newest
Oldest Most Voted
Inline Feedbacks
View all comments
Jason Mitchell
Jason Mitchell
1 month 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