# jf gradle Run Gradle builds with Artifactory integration for dependency resolution and build information collection. This topic covers the following tasks: * [Configure Gradle for Artifactory (`jf gradle-config`)](#configuration-jf-gradle-config) * [Run Gradle builds (`jf gradle`)](#build-jf-gradle) ## When to Use Use `jf gradle` if your Java/Kotlin project uses Gradle (`build.gradle` or `build.gradle.kts`) for builds and you want dependencies resolved from Artifactory with build-info collection. For Maven-based projects, use [`jf mvn`](jf-mvn.md). ## Prerequisites * Run `jf gradle-config` in the project directory before the first build. * Configure a server with `jf config add` or `jf c add`. * Authentication to Artifactory is required. *** ## Configuration: `jf gradle-config` Generate Gradle build configuration for resolving and deploying artifacts through Artifactory. **Run this once per project before your first build.** **To configure Gradle for Artifactory:** ### Synopsis ``` jf gradle-config [options] ``` **Aliases:** `gradlec` ### Configuration Options | Flag | Default | Description | | ------------------------- | ------------------------------------------------------------------------------- | --------------------------------------------------------------- | | `--global` | `false` | Apply configuration globally for all projects | | `--server-id-resolve` | — | Artifactory server ID for dependency resolution | | `--server-id-deploy` | — | Artifactory server ID for deployment | | `--repo-resolve` | — | Repository for resolving dependencies | | `--repo-deploy` | — | Repository for deploying artifacts | | `--uses-plugin` | `false` | Set to true if the Gradle Artifactory Plugin is already applied | | `--use-wrapper` | `false` | Use the Gradle wrapper | | `--deploy-maven-desc` | `true` | Deploy Maven descriptors | | `--deploy-ivy-desc` | `true` | Deploy Ivy descriptors | | `--ivy-desc-pattern` | `[organization]/[module]/ivy-[revision].xml` | Deployment pattern for Ivy descriptors | | `--ivy-artifacts-pattern` | `[organization]/[module]/[revision]/[artifact]-[revision](-[classifier]).[ext]` | Deployment pattern for Ivy artifacts | ### Configuration Examples #### View Help ```bash jf gradle-config --help ``` #### Non-Interactive Configuration Configure Gradle with non-interactive flags: ```bash jf gradle-config --server-id-resolve= --repo-resolve= --server-id-deploy= --repo-deploy= ``` Where: * \: The server ID configured using `jf config add` * \: The name of the repository in Artifactory For example: ```bash jf gradle-config --server-id-resolve=my-server --repo-resolve=gradle-virtual --server-id-deploy=my-server --repo-deploy=gradle-local ``` ### Why Run Config First? You must run `jf gradle-config` **before** `jf gradle`. The config command creates a `.jfrog/projects/gradle.yaml` file that tells the CLI which Artifactory repositories to resolve from and deploy to. Without it, `jf gradle` cannot integrate with Artifactory. If you skip this step, you will see the error: `no config file was found! Before running the 'jf gradle' command on a project for the first time, the project should be configured with the 'jf gradle-config' command`. > **Shortcut**: In CI/CD, pass all flags non-interactively so the config step is fully automated and reproducible. ### Configuration Notes * **Run once per project**: Configuration persists in `.jfrog/projects/`. Re-run when changing repository assignments. * **Global vs project**: Use `--global` for all Gradle projects on the machine. Without it, configuration is project-specific. * **Artifactory Plugin**: If your `build.gradle` already applies the Gradle Artifactory Plugin, set `--uses-plugin=true` to avoid conflicts. * **Wrapper support**: Use `--use-wrapper=true` if your project uses the Gradle wrapper (`gradlew`). * **Ivy descriptors**: The `--deploy-ivy-desc` and `--ivy-desc-pattern` flags control Ivy descriptor deployment. Most modern projects use Maven descriptors (`--deploy-maven-desc`). ### Expected Output ``` $ jf gradle-config --server-id-resolve=my-server --repo-resolve=gradle-virtual --server-id-deploy=my-server --repo-deploy=gradle-local Gradle build configuration saved successfully. ``` ### How to Verify After running, confirm the configuration exists: ```bash cat .jfrog/projects/gradle.yaml ``` *** ## Build: `jf gradle` Run Gradle build with Artifactory integration for dependency resolution and build information collection. **To run a Gradle build with Artifactory integration:** ### Synopsis ``` jf gradle [options] ``` **Aliases:** none ### Arguments | Argument | Required | Description | | ------------------- | -------- | -------------------------------------------------------------------------- | | `tasks-and-options` | Yes | Gradle tasks and options (for example, `build`, `-b path/to/build.gradle`) | ### Build Options | Flag | Default | Description | | -------------------- | ------- | --------------------------------------------------------------------------------------------------------- | | `--build-name` | — | Build name for build information (requires `--build-number`) | | `--build-number` | — | Build number for build information (requires `--build-name`) | | `--project` | — | JFrog Artifactory project key | | `--module` | — | Optional module name for build information | | `--detailed-summary` | `false` | Include affected files in the command summary | | `--threads` | `3` | Number of threads for uploading build artifacts | | `--server-id` | — | Server ID configured with `jf config add` | | `--scan` | `false` | Scan all files with Xray on the local file system before upload; skip upload if vulnerabilities are found | | `--format` | `table` | Output format for the `--scan` option. Accepts `table`, `json`, `simple-json`, or `sarif` | ### Build Examples #### Build and Publish Build Information ```bash jf gradle build --build-name= --build-number= ``` Where: * \: A name for the build (for example, `my-java-app`) * \: A number or identifier for the build run (for example, `1`) For example: ```bash jf gradle build --build-name=my-java-app --build-number=1 ``` #### Build with Custom Threads ```bash jf gradle clean build --build-name=my-app --build-number=1 --threads=5 ``` *** ## Important Notes * **Build-info publishing**: Using `--build-name` and `--build-number` only collects build info. Publish with `jf rt build-publish `. * **Gradle tasks**: All standard Gradle tasks and flags work (`clean`, `build`, `test`, `-x`, `-b`, and others). * **Artifactory Plugin**: If your `build.gradle` already applies the Gradle Artifactory Plugin, set `--uses-plugin` in `jf gradle-config` to avoid conflicts. * **Hidden flag — `--module`**: The `--module` flag is functional and collected by the build-info framework, but does not appear in `jf gradle --help` output. It works when passed on the command line alongside `--build-name` and `--build-number`. ## Selecting Publications for Gradle If you run `jf gradle clean artifactoryPublish` and the build succeeds but no artifacts are deployed, the Artifactory Gradle plugin likely does not know which publication(s) to publish. You can specify them in any of the following ways: **Option 1 — `gradle.properties`** ``` artifactory.publish.publications=release # Or multiple: # artifactory.publish.publications=release,debug ``` **Option 2 — Command line project property** ```bash jf gradle clean artifactoryPublish \ -Partifactory.publish.publications=release \ --build-name="MyApplicationAndroidBuild" \ --build-number="1" \ --project="test" ``` **Option 3 — In your build script** ```kotlin // build.gradle.kts extra["artifactory.publish.publications"] = "release" // build.gradle (Groovy) // ext["artifactory.publish.publications"] = "release" ``` These options work because `jf gradle` passes flags/properties through to the Gradle client, and the Artifactory Gradle plugin's `artifactoryPublish` task publishes the specified publication(s). Verify that the publication (e.g., `release`) actually exists in your Gradle publishing block and that your Android/Gradle setup creates a Maven Publication for it. ## Native Mode Gradle supports **Native Mode**, which bypasses `jf gradle-config` and all `.jfrog/` YAML configuration. In this mode, no Artifactory Gradle plugin is injected — you must configure Gradle to resolve from Artifactory manually. Pass `--server-id` to specify the server. Build-info **is still collected** when `--build-name` and `--build-number` are provided. Enable with: `export JFROG_RUN_NATIVE=true` For full setup instructions, per-tool comparison, and when to use each mode, see [Native Mode](native-mode.md). ## Platform Notes * **Windows:** The Gradle init script is written to `%USERPROFILE%\.gradle\init.d\`. If `JAVA_HOME` is set, the script uses Java's `user.home` property, which may differ from `%USERPROFILE%`. * **Gradle wrapper:** On Unix, ensure `gradlew` has execute permissions (`chmod +x gradlew`). On Windows, use `gradlew.bat` automatically. *** ## Environment Variables | Variable | Default | Description | | ----------------------------- | ---------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `JFROG_CLI_RELEASES_REPO` | — | Configured Artifactory repository name from which to download the JAR needed by the gradle command. Format: `/`. The repository should proxy `https://releases.jfrog.io`. | | `JFROG_CLI_DEPENDENCIES_DIR` | `$JFROG_CLI_HOME_DIR/dependencies` | Directory to which JFrog CLI's internal dependencies are downloaded. | | `JFROG_CLI_EXTRACTORS_REMOTE` | — | Alternative to `JFROG_CLI_RELEASES_REPO` for offline environments. Format: `/`. | *** ## Downloading the Maven and Gradle Extractor JARs For integration with Maven and Gradle, JFrog CLI uses build-info-extractor JAR files. These JARs are downloaded by JFrog CLI from JFrog's distribution (`releases.jfrog.io`) the first time they are needed. **Air-gapped or offline?** See [Air-Gapped and Offline Setup](air-gapped-setup.md) for a step-by-step guide. Quick setup: 1. Create a remote Maven repository in Artifactory and name it `extractors`. Configure it to proxy `https://releases.jfrog.io/artifactory/oss-release-local`. 2. Verify that this Artifactory server is configured in JFrog CLI using `jf c show`. 3. Set the `JFROG_CLI_EXTRACTORS_REMOTE` environment variable. The value should be the Server ID followed by a slash and the repository name. For example: `my-rt-server/extractors`. *** ## CI/CD Example (GitHub Actions) ```yaml # .github/workflows/build.yml steps: - uses: actions/checkout@v4 - name: Setup JFrog CLI uses: jfrog/setup-jfrog-cli@v4 env: JF_URL: ${{ vars.JF_URL }} JF_ACCESS_TOKEN: ${{ secrets.JF_ACCESS_TOKEN }} - name: Configure Gradle run: jf gradle-config --server-id-resolve=setup-jfrog-cli-server --repo-resolve=gradle-virtual --server-id-deploy=setup-jfrog-cli-server --repo-deploy=gradle-local - name: Build with Gradle run: jf gradle clean build --build-name=my-java-app --build-number=${{ github.run_number }} - name: Publish build info run: jf rt build-publish my-java-app ${{ github.run_number }} ``` ## Troubleshooting | Symptom | Cause | Fix | | ------------------------------------------------ | ----------------------------------------------------------------------- | -------------------------------------------------------------------------------------------- | | `no config file was found` | `jf gradle-config` was not run | Run `jf gradle-config` in the project directory | | 404 on dependency resolution | Resolution repository does not exist or name is wrong | Verify `--repo-resolve` matches an existing Artifactory repository | | 401 / 403 errors | Invalid credentials or insufficient permissions | Re-run `jf config add` with a valid access token | | Build succeeds but no artifacts deployed | Artifactory Gradle plugin does not know which publication(s) to publish | Set `artifactory.publish.publications=release` in `gradle.properties` or via `-P` flag | | Conflict with existing Artifactory Gradle plugin | Plugin applied twice | Set `--uses-plugin=true` in `jf gradle-config` | | Extractor JAR download fails | No internet access on build machine | Set `JFROG_CLI_EXTRACTORS_REMOTE` to an Artifactory remote repo proxying `releases.jfrog.io` | | Gradle wrapper not used | Wrapper not enabled in config | Set `--use-wrapper=true` in `jf gradle-config` | **Enable debug logging:** `export JFROG_CLI_LOG_LEVEL=DEBUG`
## Related Topics * [Build Tools Overview](/artifactory/docs/build-tool-commands) — Capabilities matrix and tool reference * [Native Mode](/artifactory/docs/native-mode) — Supported packages with Native Mode