Gradle


Overview

Gradle is a build automation tool for Java and JVM-based projects. It uses a Groovy or Kotlin DSL for build scripts, offering flexibility and performance for complex builds.

Integrating Gradle with JFrog Fly allows you to manage your artifacts and releases from source code to production in a simple and native way, directly from your IDE.


Supported Clients

JFrog Fly supports Gradle artifacts with:

  • Gradle CLI (./gradlew publish, ./gradlew build) - The Gradle build tool with wrapper

Upload / Publish Artifact

With Fly App

Activate Gradle in your Fly App to configure Gradle globally with Fly. The Fly App automatically creates an init script at ~/.gradle/init.d/ that configures both dependency resolution and publishing.

Then publish as usual:

./gradlew publish

Manual Configuration

1. Generate an access token in Fly Token Management

2. Configure Gradle:

Option A: Project Configuration

Edit build.gradle:

plugins {
    id 'java'
    id 'maven-publish'
}

repositories {
    maven {
        url "https://<your-fly-subdomain>.jfrog.io/artifactory/maven"
        credentials {
            username = "<your-fly-username>"
            password = "<your-fly-token>"
        }
    }
}

publishing {
    publications {
        maven(MavenPublication) {
            from components.java
        }
    }
    repositories {
        maven {
            url "https://<your-fly-subdomain>.jfrog.io/artifactory/maven"
            credentials {
                username = "<your-fly-username>"
                password = "<your-fly-token>"
            }
        }
    }
}

Option B: Global Configuration

Create an init script at ~/.gradle/init.d/fly.gradle:

def flyUrl = "https://<your-fly-subdomain>.jfrog.io/artifactory/maven"
def flyUsername = "<your-fly-username>"
def flyToken = "<your-fly-token>"

// Configure project repositories for dependency resolution
allprojects { project ->
    project.repositories {
        maven {
            name = "Fly"
            url uri(flyUrl)
            credentials {
                username = flyUsername
                password = flyToken
            }
        }
    }
    
    // Configure publishing for projects that apply maven-publish plugin
    project.plugins.withId('maven-publish') {
        project.publishing {
            repositories {
                clear()  // Ensure Fly is the only publishing destination
                maven {
                    name = "Fly"
                    url = uri(flyUrl)
                    credentials {
                        username = flyUsername
                        password = flyToken
                    }
                }
            }
        }
    }
}

Note: This init script applies to all Gradle projects. The plugins.withId pattern ensures publishing configuration only applies to projects using the maven-publish plugin. The clear() call ensures Fly is the only publishing destination.

3. Publish artifact:

./gradlew publish

Download / Build Dependencies

With Fly App

Activate Gradle in your Fly App to configure Gradle globally with Fly. The Fly App automatically creates an init script that configures dependency resolution from Fly.

Then build as usual:

./gradlew build

Manual Configuration

1. Generate an access token in Fly Token Management

2. Configure Gradle as shown in the Publish section above (Option A or Option B).

3. Build project:

./gradlew build

From Public Registry

When you build a project with dependencies that aren’t in your Fly Registry, JFrog Fly automatically fetches them from Maven Central and caches them for future use.

./gradlew build

Upload/Download Artifacts with CI

To publish and build Gradle artifacts with CI, update your GitHub Actions workflow to include the Fly action.

Simply type in your IDE the prompt: “Configure my workflows with Fly” and Fly MCP will configure your GitHub Actions workflow yml file, as follows:

1. Add permissions (top level, after on:):

permissions:
  contents: read
  id-token: write

2. Add Fly Action (after actions/setup-java, before Gradle commands):

- name: JFrog Fly - Configure all your package managers to work with Fly registry
  uses: jfrog/fly-action@v1
  with:
    url: https://<your-fly-subdomain>.jfrog.io

GitHub Action Example

name: Build and Publish Gradle Artifact

on:
  push:
    branches: [main]

permissions:
  contents: read
  id-token: write

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout code
        uses: actions/checkout@v4

      - name: Setup Java
        uses: actions/setup-java@v4
        with:
          java-version: '17'
          distribution: 'temurin'

      - name: JFrog Fly - Configure all your package managers to work with Fly registry
        uses: jfrog/fly-action@v1
        with:
          url: https://<your-fly-subdomain>.jfrog.io

      - name: Build with Gradle
        run: ./gradlew build

      - name: Publish to Fly
        run: ./gradlew publish

Back to Package Types →