Use CircleCI version 2.1 at the top of your .circleci/config.yml file.
1
version: 2.1
Add the orbs
stanza below your version, invoking the orb:
1
2
orbs:
gradle: circleci/gradle@3.0.0
Use gradle
elements in your existing workflows and jobs.
Checkout, build, and test a Gradle project
1
2
3
4
5
6
7
version: '2.1'
orbs:
gradle: circleci/gradle@x.y
workflows:
checkout-build-test:
jobs:
- gradle/test
How to override the default executor and supply your own custom Docker image to the gradle orb jobs.
1
2
3
4
5
6
7
8
version: '2.1'
orbs:
gradle: circleci/gradle@x.y
workflows:
gradle_test:
jobs:
- gradle/test:
executor: my-executor
Publish custom results and reports.
1
2
3
4
5
6
7
8
9
10
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/
Checkout and run task in a gradle project.
PARAMETER | DESCRIPTION | REQUIRED | DEFAULT | TYPE |
---|---|---|---|---|
app_src_directory | Useful when the source of your maven 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. | No | '' | string |
cache_key | Add a custom suffix to your cache key in the event you need to work with multiple maven caches. | No | v1 | string |
command | - | No | build | string |
deps_checksum_file | 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. | No | build.gradle | string |
executor | The name of custom executor to use | No | default | executor |
wrapper_checksum_file | File to use to generate the cache checksum for the gradle wrapper. Defaults to gradlew. For example, if testing on Windows, gradlew.bat should be used instead. | No | gradlew | string |
Checkout, build and test a Gradle project.
PARAMETER | DESCRIPTION | REQUIRED | DEFAULT | TYPE |
---|---|---|---|---|
app_src_directory | Useful when the source of your maven 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. | No | '' | string |
cache_key | Add a custom suffix to your cache key in the event you need to work with multiple maven caches. | No | v1 | string |
deps_checksum_file | 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. | No | build.gradle | string |
executor | The name of custom executor to use | No | default | executor |
reports_path | Artifacts to be published | No | build/reports/ | string |
test_command | - | No | test | string |
test_results_path | Results to be published | No | build/test-results/ | string |
wrapper_checksum_file | File to use to generate the cache checksum for the gradle wrapper. Defaults to gradlew. For example, if testing on Windows, gradlew.bat should be used instead. | No | gradlew | string |
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 | DESCRIPTION | REQUIRED | DEFAULT | TYPE |
---|---|---|---|---|
reports_path | Artifacts to be published | No | build/reports/ | string |
test_results_path | Results to be published | No | build/test-results/ | string |
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` 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 | DESCRIPTION | REQUIRED | DEFAULT | TYPE |
---|---|---|---|---|
cache_key | Add a custom suffix to your cache key in the event you need to work with multiple maven caches. | No | v1 | string |
deps_checksum_file | 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. | No | build.gradle | string |
steps | - | Yes | - | steps |
wrapper_checksum_file | File to use to generate the cache checksum for the gradle wrapper. Defaults to gradlew. For example, if testing on Windows, gradlew.bat should be used instead. | No | gradlew | string |
This default Docker image is highly cached on CircleCI and contains most necessary tools needed for Gradle related projects.
PARAMETER | DESCRIPTION | REQUIRED | DEFAULT | TYPE |
---|---|---|---|---|
tag | Pick a specific cimg/openjdk image tag: https://hub.docker.com/r/cimg/openjdk/tags
| No | '13.0' | string |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
# This code is licensed from CircleCI to the user under the MIT license.
# See here for details: https://circleci.com/developer/orbs/licensing
version: 2.1
description: |
Simplify common tasks for building and testing Java projects using Gradle.
display:
home_url: https://gradle.org/
source_url: https://github.com/CircleCI-Public/gradle-orb
commands:
collect_test_results:
description: |
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.
parameters:
reports_path:
default: build/reports/
description: Artifacts to be published
type: string
test_results_path:
default: build/test-results/
description: Results to be published
type: string
steps:
- when:
condition: <<parameters.test_results_path>>
steps:
- store_test_results:
path: <<parameters.test_results_path>>
- store_artifacts:
destination: Results
path: <<parameters.test_results_path>>
- unless:
condition: <<parameters.test_results_path>>
steps:
- run:
command: |
mkdir -p /tmp/test_results/junit
find . -name '*TEST-*.xml' -exec cp -v {} /tmp/test_results/junit \;
name: Gather Test Results
- store_test_results:
path: /tmp/test_results
- store_artifacts:
destination: Results
path: /tmp/test_results
- when:
condition: <<parameters.reports_path>>
steps:
- store_artifacts:
destination: Reports
path: <<parameters.reports_path>>
- unless:
condition: <<parameters.reports_path>>
steps:
- store_artifacts:
destination: Reports
path: build/reports/tests/test/
with_cache:
description: |
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` 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`.
parameters:
cache_key:
default: v1
description: Add a custom suffix to your cache key in the event you need to work with multiple maven caches.
type: string
deps_checksum_file:
default: build.gradle
description: 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.
type: string
steps:
type: steps
wrapper_checksum_file:
default: gradlew
description: File to use to generate the cache checksum for the gradle wrapper. Defaults to gradlew. For example, if testing on Windows, gradlew.bat should be used instead.
type: string
steps:
- run:
command: |
find . -name "${PARAM_CHECKSUM_FILES}" | sort | xargs cat | shasum | awk '{print $1}' > "${CHECKSUM_SEED_LOCATION}"
environment:
CHECKSUM_SEED_LOCATION: /tmp/gradle_dep_cache_seed
PARAM_CHECKSUM_FILES: << parameters.deps_checksum_file>>
name: Generate Dependencies Checksum
- run:
command: |
find . -name "${PARAM_CHECKSUM_FILES}" | sort | xargs cat | shasum | awk '{print $1}' > "${CHECKSUM_SEED_LOCATION}"
environment:
CHECKSUM_SEED_LOCATION: /tmp/gradle_wrapper_cache_seed
PARAM_CHECKSUM_FILES: << parameters.wrapper_checksum_file>>
name: Generate Wrapper Checksum
- restore_cache:
key: gradle-<< parameters.cache_key>>-{{ checksum "/tmp/gradle_dep_cache_seed" }}
- restore_cache:
key: gradle-<< parameters.cache_key>>-{{ checksum "/tmp/gradle_wrapper_cache_seed" }}
- steps: << parameters.steps >>
- save_cache:
key: gradle-<< parameters.cache_key>>-{{ checksum "/tmp/gradle_dep_cache_seed" }}
paths:
- ~/.gradle/caches
- save_cache:
key: gradle-<< parameters.cache_key>>-{{ checksum "/tmp/gradle_wrapper_cache_seed" }}
paths:
- ~/.gradle/wrapper
executors:
default:
description: |
This default Docker image is highly cached on CircleCI and contains most necessary tools needed for Gradle related projects.
docker:
- image: cimg/openjdk:<<parameters.tag>>
parameters:
tag:
default: "13.0"
description: |
Pick a specific cimg/openjdk image tag: https://hub.docker.com/r/cimg/openjdk/tags
type: string
jobs:
run:
description: |
Checkout and run task in a gradle project.
executor: << parameters.executor >>
parameters:
app_src_directory:
default: ""
description: Useful when the source of your maven 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.
type: string
cache_key:
default: v1
description: Add a custom suffix to your cache key in the event you need to work with multiple maven caches.
type: string
command:
default: build
type: string
deps_checksum_file:
default: build.gradle
description: 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.
type: string
executor:
default: default
description: The name of custom executor to use
type: executor
wrapper_checksum_file:
default: gradlew
description: File to use to generate the cache checksum for the gradle wrapper. Defaults to gradlew. For example, if testing on Windows, gradlew.bat should be used instead.
type: string
steps:
- checkout
- with_cache:
cache_key: << parameters.cache_key >>
deps_checksum_file: << parameters.deps_checksum_file >>
steps:
- run:
command: ./gradlew << parameters.command >>
name: Run Task
working_directory: << parameters.app_src_directory >>
wrapper_checksum_file: << parameters.wrapper_checksum_file >>
test:
description: |
Checkout, build and test a Gradle project.
executor: << parameters.executor >>
parameters:
app_src_directory:
default: ""
description: Useful when the source of your maven 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.
type: string
cache_key:
default: v1
description: Add a custom suffix to your cache key in the event you need to work with multiple maven caches.
type: string
deps_checksum_file:
default: build.gradle
description: 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.
type: string
executor:
default: default
description: The name of custom executor to use
type: executor
reports_path:
default: build/reports/
description: Artifacts to be published
type: string
test_command:
default: test
type: string
test_results_path:
default: build/test-results/
description: Results to be published
type: string
wrapper_checksum_file:
default: gradlew
description: File to use to generate the cache checksum for the gradle wrapper. Defaults to gradlew. For example, if testing on Windows, gradlew.bat should be used instead.
type: string
steps:
- checkout
- with_cache:
cache_key: << parameters.cache_key >>
deps_checksum_file: << parameters.deps_checksum_file >>
steps:
- run:
command: ./gradlew << parameters.test_command >>
name: Run Tests
working_directory: << parameters.app_src_directory >>
wrapper_checksum_file: << parameters.wrapper_checksum_file >>
- collect_test_results:
reports_path: <<parameters.reports_path>>
test_results_path: <<parameters.test_results_path>>
examples:
build_and_test:
description: Checkout, build, and test a Gradle project
usage:
version: "2.1"
orbs:
gradle: circleci/gradle@x.y
workflows:
checkout-build-test:
jobs:
- gradle/test
custom_executor:
description: |
How to override the default executor and supply your own custom Docker image to the gradle orb jobs.
usage:
version: "2.1"
orbs:
gradle: circleci/gradle@x.y
workflows:
gradle_test:
jobs:
- gradle/test:
executor: my-executor
custom_reports:
description: |
Publish custom results and reports.
usage:
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/