> For the complete CircleCI developer hub index, see [llms.txt](https://circleci.com/developer/llms.txt)

# circleci/gradle

Simplify common tasks for building and testing Java projects using Gradle.


## Commands

### collect_test_results

Store test reports to build artifacts.
Locate any JUnit test reports and store them as build artifacts and test results.
Store the HTML build report to build artifacts.


| Parameter | Type | Default | Description |
|---|---|---|---|
| `reports_path` | string | build/reports/ | Artifacts to be published |
| `test_results_path` | string | build/test-results/ | Results to be published |

### with_cache

Run a set of steps with gradle dependencies cached.
This command will first restore a cache of gradle dependencies, if one was
saved by a previous build. The provided `steps` will then be executed, and
if successful, then a fresh cache will be saved, if required.
The contents of the `~/.gradle/cache` directory is cached, which will substantially
improve build times for projects with many dependencies.
The cache-key is generated from any files named `build.gradle` that are
present in the `working_directory`.


| Parameter | Type | Default | Description |
|---|---|---|---|
| `cache_key` | string | v1 | Add a custom suffix to your cache key in the event you need to work with multiple gradle caches. |
| `deps_checksum_file` | string | build.gradle, build.gradle.kts, settings.gradle, settings.gradle.kts, libs.versions.toml | Files to use to generate the cache checksum for dependencies. Defaults to build.gradle. For example if using Gradle Kotlin DSL then set to build.gradle.kts instead. To use multiple files separate each with commas for example 'build.gradle.kts, settings.gradle.kts, libs.versions.toml' |
| `steps` | steps |  |  |

## Jobs

### run

Checkout and run task in a gradle project.


| Parameter | Type | Default | Description |
|---|---|---|---|
| `app_src_directory` | string |  | Useful when the source of your gradle project is not in the root directory of your git repo. Supply the name of the directory or relative path of the directory containing your source code. |
| `cache_key` | string | v1 | Add a custom suffix to your cache key in the event you need to work with multiple gradle caches. |
| `checkout_type` | enum | blobless |  |
| `command` | string | build |  |
| `deps_checksum_file` | string | build.gradle | File to use to generate the cache checksum for dependencies. Defaults to build.gradle. For example if using Gradle Kotlin DSL then set to build.gradle.kts instead. |
| `executor` | executor | default | The name of custom executor to use |

### test

Checkout, build and test a Gradle project.


| Parameter | Type | Default | Description |
|---|---|---|---|
| `app_src_directory` | string |  | Useful when the source of your gradle project is not in the root directory of your git repo. Supply the name of the directory or relative path of the directory containing your source code. |
| `cache_key` | string | v1 | Add a custom suffix to your cache key in the event you need to work with multiple gradle caches. |
| `checkout_type` | enum | blobless |  |
| `deps_checksum_file` | string | build.gradle, build.gradle.kts, settings.gradle.kts, libs.versions.toml | File to use to generate the cache checksum for dependencies. Defaults to build.gradle. For example if using Gradle Kotlin DSL then set to build.gradle.kts instead. |
| `executor` | executor | default | The name of custom executor to use |
| `reports_path` | string | build/reports/ | Artifacts to be published |
| `test_command` | string | test |  |
| `test_results_path` | string | build/test-results/ | Results to be published |

## Executors

### default

This default Docker image is highly cached on CircleCI and contains most necessary tools needed for Gradle related projects.


| Parameter | Type | Default | Description |
|---|---|---|---|
| `tag` | string | 11.0 | Pick a specific cimg/openjdk image tag: https://hub.docker.com/r/cimg/openjdk/tags
 |

## Examples

### build_and_test

Checkout, build, and test a Gradle project

```yaml
version: '2.1'
orbs:
  gradle: circleci/gradle@x.y
workflows:
  checkout-build-test:
    jobs:
      - gradle/test
```

### custom_executor

How to override the default executor and supply your own custom Docker image to the gradle orb jobs.


```yaml
version: '2.1'
orbs:
  gradle: circleci/gradle@x.y
workflows:
  gradle_test:
    jobs:
      - gradle/test:
          executor: my-executor
```

### custom_reports

Publish custom results and reports.


```yaml
version: '2.1'
orbs:
  gradle: circleci/gradle@x.y
workflows:
  test-with-custom-reports:
    jobs:
      - gradle/test:
          store_artifacts: build/reports/
          test_command: myTests
          test_results_path: build/test-results/
```