Turn Your Vehicle Into a Smart Earning Asset

While you’re not driving your car or bike, it can still be working for you. MOTOSHARE helps you earn passive income by connecting your vehicle with trusted renters in your city.

🚗 You set the rental price
🔐 Secure bookings with verified renters
📍 Track your vehicle with GPS integration
💰 Start earning within 48 hours

Join as a Partner Today

It’s simple, safe, and rewarding. Your vehicle. Your rules. Your earnings.

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


Subscribe
Notify of
guest
0 Comments
Newest
Oldest Most Voted
Inline Feedbacks
View all comments

Certification Courses

DevOpsSchool has introduced a series of professional certification courses designed to enhance your skills and expertise in cutting-edge technologies and methodologies. Whether you are aiming to excel in development, security, or operations, these certifications provide a comprehensive learning experience. Explore the following programs:

DevOps Certification, SRE Certification, and DevSecOps Certification by DevOpsSchool

Explore our DevOps Certification, SRE Certification, and DevSecOps Certification programs at DevOpsSchool. Gain the expertise needed to excel in your career with hands-on training and globally recognized certifications.

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