├── .bazelci └── presubmit.yml ├── .gitignore ├── AUTHORS ├── CODEOWNERS ├── CONTRIBUTING.md ├── CONTRIBUTORS ├── LICENSE.txt ├── README.md ├── WORKSPACE ├── example └── src │ └── main │ └── groovy │ ├── app │ ├── BUILD │ └── GroovyApp.groovy │ └── lib │ ├── BUILD │ ├── GroovyLib.groovy │ └── JavaLib.java └── groovy ├── BUILD ├── groovy.bzl └── repositories.bzl /.bazelci/presubmit.yml: -------------------------------------------------------------------------------- 1 | --- 2 | platforms: 3 | ubuntu1804: 4 | build_targets: 5 | - "//..." 6 | rbe_ubuntu1604: 7 | build_targets: 8 | - "//..." 9 | macos: 10 | build_targets: 11 | - "//..." 12 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /bazel-* 2 | 3 | # Ignore IntelliJ library files 4 | .ijwb 5 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | # This the official list of Bazel authors for copyright purposes. 2 | # This file is distinct from the CONTRIBUTORS files. 3 | # See the latter for an explanation. 4 | 5 | # Names should be added to this file as: 6 | # Name or Organization 7 | # The email address is not required for organizations. 8 | 9 | Google Inc. 10 | Damien Martin-Guillerez 11 | David Chen 12 | Erik Kuefler 13 | Kristina Chodorow 14 | -------------------------------------------------------------------------------- /CODEOWNERS: -------------------------------------------------------------------------------- 1 | * @ekuefler 2 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | Want to contribute? Great! First, read this page (including the small print at the end). 2 | 3 | ### Before you contribute 4 | **Before we can use your code, you must sign the 5 | [Google Individual Contributor License Agreement](https://developers.google.com/open-source/cla/individual?csw=1) 6 | (CLA)**, which you can do online. 7 | 8 | The CLA is necessary mainly because you own the copyright to your changes, 9 | even after your contribution becomes part of our codebase, so we need your 10 | permission to use and distribute your code. We also need to be sure of 11 | various other things — for instance that you'll tell us if you know that 12 | your code infringes on other people's patents. You don't have to sign 13 | the CLA until after you've submitted your code for review and a member has 14 | approved it, but you must do it before we can put your code into our codebase. 15 | 16 | Before you start working on a larger contribution, you should get in touch 17 | with us first. Use the issue tracker to explain your idea so we can help and 18 | possibly guide you. 19 | 20 | ### Code reviews and other contributions. 21 | **All submissions, including submissions by project members, require review.** 22 | Please follow the instructions in [the contributors documentation](http://bazel.io/contributing.html). 23 | 24 | ### The small print 25 | Contributions made by corporations are covered by a different agreement than 26 | the one above, the 27 | [Software Grant and Corporate Contributor License Agreement](https://cla.developers.google.com/about/google-corporate). 28 | -------------------------------------------------------------------------------- /CONTRIBUTORS: -------------------------------------------------------------------------------- 1 | # People who have agreed to one of the CLAs and can contribute patches. 2 | # The AUTHORS file lists the copyright holders; this file 3 | # lists people. For example, Google employees are listed here 4 | # but not in AUTHORS, because Google holds the copyright. 5 | # 6 | # https://developers.google.com/open-source/cla/individual 7 | # https://developers.google.com/open-source/cla/corporate 8 | # 9 | # Names should be added to this file as: 10 | # Name 11 | 12 | Damien Martin-Guillerez 13 | David Chen 14 | Erik Kuefler 15 | Kristina Chodorow 16 | Justine Alexandra Roberts Tunney 17 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright [yyyy] [name of copyright owner] 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. 203 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![Build status](https://badge.buildkite.com/5745498acd50b9811f2bdb2fc26defd3c3f01bed96ffe6fb5a.svg)](https://buildkite.com/bazel/rules-groovy-postsubmit) 2 | 3 | # 📣 [Unmaintained] Groovy Rules 4 | 5 | > [!WARNING] 6 | > Due to an absence of any maintainers, this repository is archived and currently unmaintained. 7 | > 8 | > **We discourage any new dependencies on the contents of this repository.** 9 | > 10 | > If you, or your organization, are interested in revitalizing this project by taking over its maintenance, we welcome your initiative. 11 | > To discuss the process of un-archiving and assuming ownership of this repository, please reach out to us via email at `bazel-contrib@googlegroups.com` or join the conversation on our Slack workspace in the `#rules` channel. 12 | > You can sign up for Slack access at [https://slack.bazel.build](https://slack.bazel.build). 13 | 14 |
15 |

Rules

16 | 23 |
24 | 25 | ## Overview 26 | 27 | These build rules are used for building [Groovy](http://www.groovy-lang.org/) 28 | projects with Bazel. Groovy libraries may interoperate with and depend on Java 29 | libraries and vice-versa. 30 | 31 | 32 | ## Setup 33 | 34 | To be able to use the Groovy rules, you must provide bindings for the following 35 | targets: 36 | 37 | * `//external:groovy-sdk`, pointing at the 38 | [Groovy SDK binaries](http://www.groovy-lang.org/download.html) 39 | * `//external:groovy`, pointing at the Groovy core language jar 40 | * `//external:junit`, pointing at JUnit (only required if using the test rules) 41 | * `//external:spock`, pointing at Spock (only required if using `spock_test`) 42 | 43 | The easiest way to do so is to add the following to your `WORKSPACE` file: 44 | 45 | ```python 46 | load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") 47 | http_archive( 48 | name = "io_bazel_rules_groovy", 49 | url = "https://github.com/bazelbuild/rules_groovy/archive/0.0.6.tar.gz", 50 | sha256 = "21c7172786623f280402d3b3a2fc92f36568afad5a4f6f5ea38fd1c6897aecf8", 51 | strip_prefix = "rules_groovy-0.0.6", 52 | ) 53 | load("@io_bazel_rules_groovy//groovy:repositories.bzl", "rules_groovy_dependencies") 54 | rules_groovy_dependencies() 55 | ``` 56 | 57 | 58 | ## Basic Example 59 | 60 | Suppose you have the following directory structure for a simple Groovy and Java 61 | application: 62 | 63 | ``` 64 | [workspace]/ 65 | WORKSPACE 66 | src/main/groovy/ 67 | app/ 68 | BUILD 69 | GroovyApp.groovy 70 | lib/ 71 | BUILD 72 | GroovyLib.groovy 73 | JavaLib.java 74 | src/test/groovy/ 75 | lib/ 76 | BUILD 77 | LibTest.groovy 78 | ``` 79 | 80 | Then, to build the code under src/main/groovy/lib/, your 81 | `src/main/groovy/lib/BUILD` can look like this: 82 | 83 | ```python 84 | load("@io_bazel_rules_groovy//groovy:groovy.bzl", "groovy_library") 85 | 86 | groovy_library( 87 | name = "groovylib", 88 | srcs = glob(["*.groovy"]), 89 | visibility = ["//visibility:public"], 90 | deps = [ 91 | ":javalib", 92 | ], 93 | ) 94 | 95 | java_library( 96 | name = "javalib", 97 | srcs = glob(["*.java"]), 98 | ) 99 | ``` 100 | 101 | For simplicity, you can combine Groovy and Java sources into a single library 102 | using `groovy_and_java_library`. Note that this allows the Groovy code to 103 | reference the Java code, but not vice-versa. Your `src/main/groovy/lib/BUILD` 104 | file would then look like this: 105 | 106 | ```python 107 | load("@io_bazel_rules_groovy//groovy:groovy.bzl", "groovy_and_java_library") 108 | 109 | groovy_and_java_library( 110 | name = "lib", 111 | srcs = glob(["*.groovy", "*.java"]), 112 | ) 113 | ``` 114 | 115 | To build the application under src/main/groovy/app, you can define a binary 116 | using `groovy_binary` as follows: 117 | 118 | ```python 119 | load("@io_bazel_rules_groovy//groovy:groovy.bzl", "groovy_binary") 120 | 121 | groovy_binary( 122 | name = "GroovyApp", 123 | srcs = glob(["*.groovy"]), 124 | main_class = "app.GroovyApp", 125 | deps = [ 126 | "//src/main/groovy/lib:groovylib", 127 | ], 128 | ) 129 | ``` 130 | 131 | Finally, you can write tests in Groovy using `groovy_test`. The `srcs` of this 132 | rule will be converted into names of class files that are passed to JUnit. For 133 | this to work, the test sources must be under src/test/groovy or src/test/java. 134 | To build the test under src/test/groovy/lib, your BUILD file would look like 135 | this: 136 | 137 | ```python 138 | load("@io_bazel_rules_groovy//groovy:groovy.bzl", "groovy_test", "groovy_library") 139 | 140 | 141 | groovy_library( 142 | name = "testlib", 143 | srcs = glob(["*.groovy"]), 144 | ) 145 | 146 | groovy_test( 147 | name = "LibTest", 148 | srcs = ["LibTest.groovy"], 149 | deps = [":testlib"], 150 | ) 151 | ``` 152 | 153 | If you're using JUnit or Spock, see 154 | groovy_junit_test or 155 | spock_test for wrappers that make testing with these 156 | systems slightly more convenient. 157 | 158 | 159 | ## groovy_library 160 | 161 | ```python 162 | groovy_library(name, srcs, deps, **kwargs) 163 | ``` 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 182 | 183 | 184 | 185 | 189 | 190 | 191 | 192 | 203 | 204 | 205 | 206 | 213 | 214 | 215 |
Attributes
name 179 | Name, required 180 |

A unique name for this rule.

181 |
srcs 186 | List of labels, required 187 |

List of .groovy source files used to build the library.

188 |
deps 193 | List of labels or .jar files, optional 194 |

195 | List of other libraries to be included on the compile-time classpath 196 | when building this library. 197 |

198 |

199 | These can be either other `groovy_library` targets, `java_library` 200 | targets, `groovy_and_java_library` targets, or raw .jar files. 201 |

202 |
**kwargs 207 | see java_binary 208 |

209 | The other arguments of this rule will be passed to the `java_import` 210 | that wraps the groovy library. 211 |

212 |
216 | 217 | 218 | ## groovy\_and\_java\_library 219 | 220 | ```python 221 | groovy_and_java_library(name, srcs, deps, **kwargs) 222 | ``` 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 241 | 242 | 243 | 244 | 248 | 249 | 250 | 251 | 262 | 263 | 264 | 265 | 272 | 273 | 274 |
Attributes
name 238 | Name, required 239 |

A unique name for this rule.

240 |
srcs 245 | List of labels, required 246 |

List of .groovy and .java source files used to build the library.

247 |
deps 252 | List of labels or .jar files, optional 253 |

254 | List of other libraries to be included on the compile-time classpath 255 | when building this library. 256 |

257 |

258 | These can be either other `groovy_library` targets, `java_library` 259 | targets, `groovy_and_java_library` targets, or raw .jar files. 260 |

261 |
**kwargs 266 | see java_binary 267 |

268 | The other arguments of this rule will be passed to the `java_import` 269 | that wraps the groovy library. 270 |

271 |
275 | 276 | 277 | ## groovy_binary 278 | 279 | ```python 280 | groovy_binary(name, main_class, srcs, deps, **kwargs) 281 | ``` 282 | 283 | 284 | 285 | 286 | 287 | 288 | 289 | 290 | 291 | 292 | 293 | 294 | 295 | 296 | 300 | 301 | 302 | 303 | 312 | 313 | 314 | 315 | 319 | 320 | 321 | 322 | 334 | 335 | 336 | 337 | 344 | 345 | 346 |
Attributes
name 297 | Name, required 298 |

A unique name for this rule.

299 |
main_class 304 | String, required 305 |

306 | The name of either a class containing a `main` method or a Groovy 307 | script file to use as an entry point (see 308 | 309 | here for more details on scripts vs. classes). 310 |

311 |
srcs 316 | List of labels, required 317 |

List of .groovy source files used to build the application.

318 |
deps 323 | List of labels or .jar files, optional 324 |

325 | List of other libraries to be included on both the compile-time 326 | classpath when building this application and the runtime classpath 327 | when executing it. 328 |

329 |

330 | These can be `groovy_library` targets, `java_library` targets, 331 | `groovy_and_java_library` targets, or raw .jar files. 332 |

333 |
**kwargs 338 | see java_binary 339 |

340 | The other arguments of this rule will be passed to the `java_binary` 341 | underlying the `groovy_binary`. 342 |

343 |
347 | 348 | 349 | ## groovy_test 350 | 351 | ```python 352 | groovy_test(name, deps, srcs, data, resources, jvm_flags, size, tags) 353 | ``` 354 | 355 | 356 | 357 | 358 | 359 | 360 | 361 | 362 | 363 | 364 | 365 | 366 | 367 | 368 | 372 | 373 | 374 | 375 | 382 | 383 | 384 | 385 | 396 | 397 | 398 | 399 | 407 | 408 | 409 | 410 | 417 | 418 | 419 |
Attributes
name 369 | Name, required 370 |

A unique name for this rule.

371 |
srcs 376 | List of labels, required 377 |

378 | List of .groovy source files whose names will be converted to classes 379 | passed to JUnitCore. 380 |

381 |
deps 386 | List of labels or .jar files, optional 387 |

388 | List of libraries to be included on both the compile-time classpath 389 | when building this test and on the runtime classpath when executing it. 390 |

391 |

392 | These can be `groovy_library` targets, `java_library` targets, 393 | `groovy_and_java_library` targets, or raw .jar files. 394 |

395 |
resources 400 | List of labels, optional 401 |

402 | A list of data files to include on the test's classpath. This is 403 | accomplished by creating a `java_library` containing only the specified 404 | resources and including that library in the test's dependencies. 405 |

406 |
jvm_flags 411 | List of strings, optional 412 |

413 | A list of flags to embed in the wrapper script generated for running 414 | this binary. 415 |

416 |
420 | 421 | 422 | ## groovy_junit_test 423 | 424 | ```python 425 | groovy_junit_test(name, tests, deps, groovy_srcs, java_srcs, data, resources, jvm_flags, size, tags) 426 | ``` 427 | 428 | 429 | 430 | 431 | 432 | 433 | 434 | 435 | 436 | 437 | 438 | 439 | 440 | 441 | 445 | 446 | 447 | 448 | 455 | 456 | 457 | 458 | 465 | 466 | 467 | 468 | 475 | 476 | 477 | 478 | 489 | 490 | 491 | 492 | 500 | 501 | 502 | 503 | 510 | 511 | 512 |
Attributes
name 442 | Name, required 443 |

A unique name for this rule.

444 |
tests 449 | List of labels, required 450 |

451 | List of .groovy source files that will be used as test specifications 452 | that will be executed by JUnit. 453 |

454 |
groovy_srcs 459 | List of labels, optional 460 |

461 | List of additional .groovy source files that will be used to build the 462 | test. 463 |

464 |
java_srcs 469 | List of labels, optional 470 |

471 | List of additional .java source files that will be used to build the 472 | test. 473 |

474 |
deps 479 | List of labels or .jar files, optional 480 |

481 | List of libraries to be included on both the compile-time classpath 482 | when building this test and on the runtime classpath when executing it. 483 |

484 |

485 | These can be `groovy_library` targets, `java_library` targets, 486 | `groovy_and_java_library` targets, or raw .jar files. 487 |

488 |
resources 493 | List of labels, optional 494 |

495 | A list of data files to include on the test's classpath. This is 496 | accomplished by creating a `java_library` containing only the specified 497 | resources and including that library in the test's dependencies. 498 |

499 |
jvm_flags 504 | List of strings, optional 505 |

506 | A list of flags to embed in the wrapper script generated for running 507 | this binary. 508 |

509 |
513 | 514 | 515 | ## spock_test 516 | 517 | ```python 518 | spock_test(name, specs, deps, groovy_srcs, java_srcs, data, resources, jvm_flags, size, tags) 519 | ``` 520 | 521 | 522 | 523 | 524 | 525 | 526 | 527 | 528 | 529 | 530 | 531 | 532 | 533 | 534 | 538 | 539 | 540 | 541 | 548 | 549 | 550 | 551 | 558 | 559 | 560 | 561 | 568 | 569 | 570 | 571 | 582 | 583 | 584 | 585 | 593 | 594 | 595 | 596 | 603 | 604 | 605 |
Attributes
name 535 | Name, required 536 |

A unique name for this rule.

537 |
specs 542 | List of labels, required 543 |

544 | List of .groovy source files that will be used as test specifications 545 | that will be executed by JUnit. 546 |

547 |
groovy_srcs 552 | List of labels, optional 553 |

554 | List of additional .groovy source files that will be used to build the 555 | test. 556 |

557 |
java_srcs 562 | List of labels, optional 563 |

564 | List of additional .java source files that will be used to build the 565 | test. 566 |

567 |
deps 572 | List of labels or .jar files, optional 573 |

574 | List of libraries to be included on both the compile-time classpath 575 | when building this test and on the runtime classpath when executing it. 576 |

577 |

578 | These can be `groovy_library` targets, `java_library` targets, 579 | `groovy_and_java_library` targets, or raw .jar files. 580 |

581 |
resources 586 | List of labels, optional 587 |

588 | A list of data files to include on the test's classpath. This is 589 | accomplished by creating a `java_library` containing only the specified 590 | resources and including that library in the test's dependencies. 591 |

592 |
jvm_flags 597 | List of strings, optional 598 |

599 | A list of flags to embed in the wrapper script generated for running 600 | this binary. 601 |

602 |
606 | -------------------------------------------------------------------------------- /WORKSPACE: -------------------------------------------------------------------------------- 1 | workspace(name = "io_bazel_rules_groovy") 2 | 3 | load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") 4 | 5 | http_archive( 6 | name = "bazelci_rules", 7 | sha256 = "eca21884e6f66a88c358e580fd67a6b148d30ab57b1680f62a96c00f9bc6a07e", 8 | strip_prefix = "bazelci_rules-1.0.0", 9 | url = "https://github.com/bazelbuild/continuous-integration/releases/download/rules-1.0.0/bazelci_rules-1.0.0.tar.gz", 10 | ) 11 | 12 | load("@bazelci_rules//:rbe_repo.bzl", "rbe_preconfig") 13 | 14 | # Creates a default toolchain config for RBE. 15 | # Use this as is if you are using the rbe_ubuntu16_04 container, 16 | # otherwise refer to RBE docs. 17 | rbe_preconfig( 18 | name = "buildkite_config", 19 | toolchain = "ubuntu1804-bazel-java11", 20 | ) 21 | 22 | load("//groovy:repositories.bzl", "rules_groovy_dependencies") 23 | 24 | rules_groovy_dependencies() 25 | -------------------------------------------------------------------------------- /example/src/main/groovy/app/BUILD: -------------------------------------------------------------------------------- 1 | load("@io_bazel_rules_groovy//groovy:groovy.bzl", "groovy_binary") 2 | 3 | groovy_binary( 4 | name = "GroovyApp", 5 | srcs = glob(["*.groovy"]), 6 | main_class = "app.GroovyApp", 7 | deps = [ 8 | "//example/src/main/groovy/lib:groovylib", 9 | ], 10 | ) 11 | -------------------------------------------------------------------------------- /example/src/main/groovy/app/GroovyApp.groovy: -------------------------------------------------------------------------------- 1 | package app 2 | 3 | import lib.GroovyLib 4 | 5 | lib.GroovyLib.printGreeting() 6 | -------------------------------------------------------------------------------- /example/src/main/groovy/lib/BUILD: -------------------------------------------------------------------------------- 1 | load("@io_bazel_rules_groovy//groovy:groovy.bzl", "groovy_library", "groovy_and_java_library") 2 | 3 | groovy_library( 4 | name = "groovylib", 5 | srcs = glob(["*.groovy"]), 6 | visibility = ["//visibility:public"], 7 | deps = [ 8 | ":javalib", 9 | ], 10 | ) 11 | 12 | java_library( 13 | name = "javalib", 14 | srcs = glob(["*.java"]), 15 | ) 16 | 17 | groovy_and_java_library( 18 | name = "groovyjavalib", 19 | srcs = glob(["*.groovy", "*.java"]), 20 | ) 21 | -------------------------------------------------------------------------------- /example/src/main/groovy/lib/GroovyLib.groovy: -------------------------------------------------------------------------------- 1 | package lib 2 | 3 | static void printGreeting() { 4 | println JavaLib.GREETING; 5 | } -------------------------------------------------------------------------------- /example/src/main/groovy/lib/JavaLib.java: -------------------------------------------------------------------------------- 1 | package lib; 2 | 3 | public class JavaLib { 4 | public static String GREETING = "Hello world"; 5 | } 6 | -------------------------------------------------------------------------------- /groovy/BUILD: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bazelbuild/rules_groovy/9f8cd15f32af7fd4c0347b786010b3c92f6ad45f/groovy/BUILD -------------------------------------------------------------------------------- /groovy/groovy.bzl: -------------------------------------------------------------------------------- 1 | # Copyright 2015 The Bazel Authors. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | load("@rules_java//java:defs.bzl", "java_binary", "java_import", "java_library") 16 | 17 | def _groovy_jar_impl(ctx): 18 | """Creates a .jar file from Groovy sources. Users should rely on 19 | groovy_library instead of using this rule directly. 20 | """ 21 | class_jar = ctx.outputs.class_jar 22 | build_output = class_jar.path + ".build_output" 23 | 24 | # Extract all transitive dependencies 25 | # TODO(bazel-team): get transitive dependencies from other groovy libraries 26 | all_deps = depset( 27 | ctx.files.deps, 28 | transitive = [ 29 | dep[JavaInfo].transitive_runtime_jars 30 | for dep in ctx.attr.deps 31 | if JavaInfo in dep 32 | ], 33 | ) 34 | 35 | # Set up the output directory and set JAVA_HOME 36 | cmd = "rm -rf %s\n" % build_output 37 | cmd += "mkdir -p %s\n" % build_output 38 | cmd += "export JAVA_HOME=%s\n" % ctx.attr._jdk[java_common.JavaRuntimeInfo].java_home 39 | 40 | # Set GROOVY_HOME by scanning through the groovy SDK to find the license file, 41 | # which should be at the root of the SDK. The name of the license file depends 42 | # changed with newer versions of groovy. 43 | for file in ctx.files._groovysdk: 44 | if file.basename == "CLI-LICENSE.txt" or file.basename == "LICENSE": 45 | cmd += "export GROOVY_HOME=%s\n" % file.dirname 46 | break 47 | 48 | # Compile all files in srcs with groovyc 49 | cmd += "$GROOVY_HOME/bin/groovyc %s -d %s %s\n" % ( 50 | "-cp " + ":".join([dep.path for dep in all_deps.to_list()]) if len(all_deps.to_list()) != 0 else "", 51 | build_output, 52 | " ".join([src.path for src in ctx.files.srcs]), 53 | ) 54 | 55 | # Discover all of the generated class files and write their paths to a file. 56 | # Run the paths through sed to trim out everything before the package root so 57 | # that the paths match how they should look in the jar file. 58 | cmd += "find %s -name '*.class' | sed 's:^%s/::' > %s/class_list\n" % ( 59 | build_output, 60 | build_output, 61 | build_output, 62 | ) 63 | 64 | # Create a jar file using the discovered paths 65 | cmd += "root=`pwd`\n" 66 | cmd += "cd %s; $root/%s Cc ../%s @class_list\n" % ( 67 | build_output, 68 | ctx.executable._zipper.path, 69 | class_jar.basename, 70 | ) 71 | cmd += "cd $root\n" 72 | 73 | # Clean up temporary output 74 | cmd += "rm -rf %s" % build_output 75 | 76 | # Execute the command 77 | ctx.actions.run_shell( 78 | inputs = ( 79 | ctx.files.srcs + 80 | all_deps.to_list() + ctx.files._groovysdk + ctx.files._jdk 81 | ), 82 | tools = ctx.files._zipper, 83 | outputs = [class_jar], 84 | mnemonic = "Groovyc", 85 | command = "set -e;" + cmd, 86 | use_default_shell_env = True, 87 | ) 88 | 89 | _groovy_jar = rule( 90 | attrs = { 91 | "srcs": attr.label_list( 92 | allow_empty = False, 93 | allow_files = [".groovy"], 94 | ), 95 | "deps": attr.label_list( 96 | mandatory = False, 97 | allow_files = [".jar"], 98 | ), 99 | "_groovysdk": attr.label( 100 | default = Label("//external:groovy-sdk"), 101 | ), 102 | "_jdk": attr.label( 103 | default = Label("@bazel_tools//tools/jdk:current_java_runtime"), 104 | ), 105 | "_zipper": attr.label( 106 | default = Label("@bazel_tools//tools/zip:zipper"), 107 | executable = True, 108 | allow_single_file = True, 109 | cfg = "host", 110 | ), 111 | }, 112 | outputs = { 113 | "class_jar": "lib%{name}.jar", 114 | }, 115 | implementation = _groovy_jar_impl, 116 | ) 117 | 118 | def groovy_library(name, srcs = [], testonly = 0, deps = [], **kwargs): 119 | """Rule analagous to java_library that accepts .groovy sources instead of 120 | .java sources. The result is wrapped in a java_import so that java rules may 121 | depend on it. 122 | """ 123 | _groovy_jar( 124 | name = name + "-impl", 125 | srcs = srcs, 126 | testonly = testonly, 127 | deps = deps, 128 | ) 129 | java_import( 130 | name = name, 131 | jars = [name + "-impl"], 132 | testonly = testonly, 133 | deps = deps, 134 | **kwargs 135 | ) 136 | 137 | def groovy_and_java_library(name, srcs = [], testonly = 0, deps = [], **kwargs): 138 | """Accepts .groovy and .java srcs to create a groovy_library and a 139 | java_library. The groovy_library will depend on the java_library, so the 140 | Groovy code may reference the Java code but not vice-versa. 141 | """ 142 | groovy_deps = deps 143 | jars = [] 144 | 145 | # Put all .java sources in a java_library 146 | java_srcs = [src for src in srcs if src.endswith(".java")] 147 | if java_srcs: 148 | java_library( 149 | name = name + "-java", 150 | srcs = java_srcs, 151 | testonly = testonly, 152 | deps = deps, 153 | ) 154 | groovy_deps = depset(groovy_deps + [name + "-java"]) 155 | jars += ["lib" + name + "-java.jar"] 156 | 157 | # Put all .groovy sources in a groovy_library depending on the java_library 158 | groovy_srcs = [src for src in srcs if src.endswith(".groovy")] 159 | if groovy_srcs: 160 | _groovy_jar( 161 | name = name + "-groovy", 162 | srcs = groovy_srcs, 163 | testonly = testonly, 164 | deps = groovy_deps, 165 | ) 166 | jars += ["lib" + name + "-groovy.jar"] 167 | 168 | # Output a java_import combining both libraries 169 | java_import( 170 | name = name, 171 | jars = jars, 172 | testonly = testonly, 173 | deps = deps, 174 | **kwargs 175 | ) 176 | 177 | def groovy_binary(name, main_class, srcs = [], testonly = 0, deps = [], **kwargs): 178 | """Rule analagous to java_binary that accepts .groovy sources instead of .java 179 | sources. 180 | """ 181 | all_deps = deps + ["//external:groovy"] 182 | if srcs: 183 | groovy_library( 184 | name = name + "-lib", 185 | srcs = srcs, 186 | testonly = testonly, 187 | deps = deps, 188 | ) 189 | all_deps += [name + "-lib"] 190 | java_binary( 191 | name = name, 192 | main_class = main_class, 193 | runtime_deps = all_deps, 194 | testonly = testonly, 195 | **kwargs 196 | ) 197 | 198 | def path_to_class(path): 199 | if path.startswith("src/test/groovy/"): 200 | return path[len("src/test/groovy/"):path.index(".groovy")].replace("/", ".") 201 | elif path.startswith("src/test/java/"): 202 | return path[len("src/test/java/"):path.index(".groovy")].replace("/", ".") 203 | else: 204 | fail("groovy_test sources must be under src/test/java or src/test/groovy") 205 | 206 | def _groovy_test_impl(ctx): 207 | # Collect jars from the Groovy sdk 208 | groovy_sdk_jars = [ 209 | file 210 | for file in ctx.files._groovysdk 211 | if file.basename.endswith(".jar") 212 | ] 213 | 214 | # Extract all transitive dependencies 215 | all_deps = depset( 216 | ctx.files.deps + ctx.files._implicit_deps + groovy_sdk_jars, 217 | transitive = [ 218 | dep[JavaInfo].transitive_runtime_jars 219 | for dep in ctx.attr.deps 220 | if JavaInfo in dep 221 | ], 222 | ) 223 | 224 | # Infer a class name from each src file 225 | classes = [path_to_class(src.path) for src in ctx.files.srcs] 226 | 227 | # Write a file that executes JUnit on the inferred classes 228 | cmd = "$JAVA_HOME/bin/java %s -cp %s org.junit.runner.JUnitCore %s\n" % ( 229 | " ".join(ctx.attr.jvm_flags), 230 | ":".join([dep.short_path for dep in all_deps.to_list()]), 231 | " ".join(classes), 232 | ) 233 | ctx.actions.write( 234 | output = ctx.outputs.executable, 235 | content = cmd, 236 | ) 237 | 238 | # Return all dependencies needed to run the tests 239 | return struct( 240 | runfiles = ctx.runfiles(files = all_deps.to_list() + ctx.files.data + ctx.files._jdk), 241 | ) 242 | 243 | _groovy_test = rule( 244 | attrs = { 245 | "srcs": attr.label_list( 246 | mandatory = True, 247 | allow_files = [".groovy"], 248 | ), 249 | "data": attr.label_list(allow_files = True), 250 | "jvm_flags": attr.string_list(), 251 | "deps": attr.label_list(allow_files = [".jar"]), 252 | "_groovysdk": attr.label( 253 | default = Label("//external:groovy-sdk"), 254 | ), 255 | "_implicit_deps": attr.label_list(default = [ 256 | Label("//external:junit"), 257 | ]), 258 | "_jdk": attr.label( 259 | default = Label("@bazel_tools//tools/jdk:current_java_runtime"), 260 | ), 261 | }, 262 | test = True, 263 | implementation = _groovy_test_impl, 264 | ) 265 | 266 | def groovy_test( 267 | name, 268 | deps = [], 269 | srcs = [], 270 | data = [], 271 | resources = [], 272 | jvm_flags = [], 273 | size = "medium", 274 | tags = []): 275 | # Create an extra jar to hold the resource files if any were specified 276 | all_deps = deps 277 | if resources: 278 | java_library( 279 | name = name + "-resources", 280 | resources = resources, 281 | testonly = 1, 282 | ) 283 | all_deps += [name + "-resources"] 284 | 285 | _groovy_test( 286 | name = name, 287 | size = size, 288 | tags = tags, 289 | srcs = srcs, 290 | deps = all_deps, 291 | data = data, 292 | jvm_flags = jvm_flags, 293 | ) 294 | 295 | def groovy_junit_test( 296 | name, 297 | tests, 298 | deps = [], 299 | groovy_srcs = [], 300 | java_srcs = [], 301 | data = [], 302 | resources = [], 303 | jvm_flags = [], 304 | size = "small", 305 | tags = []): 306 | groovy_lib_deps = deps + ["//external:junit"] 307 | test_deps = deps + ["//external:junit"] 308 | 309 | if len(tests) == 0: 310 | fail("Must provide at least one file in tests") 311 | 312 | # Put all Java sources into a Java library 313 | if java_srcs: 314 | java_library( 315 | name = name + "-javalib", 316 | srcs = java_srcs, 317 | testonly = 1, 318 | deps = deps + ["//external:junit"], 319 | ) 320 | groovy_lib_deps += [name + "-javalib"] 321 | test_deps += [name + "-javalib"] 322 | 323 | # Put all tests and Groovy sources into a Groovy library 324 | groovy_library( 325 | name = name + "-groovylib", 326 | srcs = tests + groovy_srcs, 327 | testonly = 1, 328 | deps = groovy_lib_deps, 329 | ) 330 | test_deps += [name + "-groovylib"] 331 | 332 | # Create a groovy test 333 | groovy_test( 334 | name = name, 335 | deps = test_deps, 336 | srcs = tests, 337 | data = data, 338 | resources = resources, 339 | jvm_flags = jvm_flags, 340 | size = size, 341 | tags = tags, 342 | ) 343 | 344 | def spock_test( 345 | name, 346 | specs, 347 | deps = [], 348 | groovy_srcs = [], 349 | java_srcs = [], 350 | data = [], 351 | resources = [], 352 | jvm_flags = [], 353 | size = "small", 354 | tags = []): 355 | groovy_lib_deps = deps + [ 356 | "//external:junit", 357 | "//external:spock", 358 | ] 359 | test_deps = deps + [ 360 | "//external:junit", 361 | "//external:spock", 362 | ] 363 | 364 | if len(specs) == 0: 365 | fail("Must provide at least one file in specs") 366 | 367 | # Put all Java sources into a Java library 368 | if java_srcs: 369 | java_library( 370 | name = name + "-javalib", 371 | srcs = java_srcs, 372 | testonly = 1, 373 | deps = deps + [ 374 | "//external:junit", 375 | "//external:spock", 376 | ], 377 | ) 378 | groovy_lib_deps += [name + "-javalib"] 379 | test_deps += [name + "-javalib"] 380 | 381 | # Put all specs and Groovy sources into a Groovy library 382 | groovy_library( 383 | name = name + "-groovylib", 384 | srcs = specs + groovy_srcs, 385 | testonly = 1, 386 | deps = groovy_lib_deps, 387 | ) 388 | test_deps += [name + "-groovylib"] 389 | 390 | # Create a groovy test 391 | groovy_test( 392 | name = name, 393 | deps = test_deps, 394 | srcs = specs, 395 | data = data, 396 | resources = resources, 397 | jvm_flags = jvm_flags, 398 | size = size, 399 | tags = tags, 400 | ) 401 | -------------------------------------------------------------------------------- /groovy/repositories.bzl: -------------------------------------------------------------------------------- 1 | # Copyright 2019 The Bazel Authors. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") 16 | load("@bazel_tools//tools/build_defs/repo:jvm.bzl", "jvm_maven_import_external") 17 | load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe") 18 | 19 | def rules_groovy_dependencies(): 20 | maybe( 21 | http_archive, 22 | name = "rules_java", 23 | urls = [ 24 | "https://mirror.bazel.build/github.com/bazelbuild/rules_java/archive/rules_java-0.1.1.tar.gz", 25 | "https://github.com/bazelbuild/rules_java/releases/download/0.1.1/rules_java-0.1.1.tar.gz", 26 | ], 27 | sha256 = "220b87d8cfabd22d1c6d8e3cdb4249abd4c93dcc152e0667db061fb1b957ee68", 28 | ) 29 | 30 | http_archive( 31 | name = "groovy_sdk_artifact", 32 | urls = [ 33 | "https://mirror.bazel.build/dl.bintray.com/groovy/maven/apache-groovy-binary-2.5.8.zip", 34 | "https://dl.bintray.com/groovy/maven/apache-groovy-binary-2.5.8.zip", 35 | ], 36 | sha256 = "49fb14b98f9fed1744781e4383cf8bff76440032f58eb5fabdc9e67a5daa8742", 37 | build_file_content = """ 38 | filegroup( 39 | name = "sdk", 40 | srcs = glob(["groovy-2.5.8/**"]), 41 | visibility = ["//visibility:public"], 42 | ) 43 | java_import( 44 | name = "groovy", 45 | jars = ["groovy-2.5.8/lib/groovy-2.5.8.jar"], 46 | visibility = ["//visibility:public"], 47 | ) 48 | """, 49 | ) 50 | native.bind( 51 | name = "groovy-sdk", 52 | actual = "@groovy_sdk_artifact//:sdk", 53 | ) 54 | native.bind( 55 | name = "groovy", 56 | actual = "@groovy_sdk_artifact//:groovy", 57 | ) 58 | 59 | jvm_maven_import_external( 60 | name = "junit_artifact", 61 | artifact = "junit:junit:4.12", 62 | server_urls = ["https://mirror.bazel.build/repo1.maven.org/maven2"], 63 | licenses = ["notice"], 64 | artifact_sha256 = "59721f0805e223d84b90677887d9ff567dc534d7c502ca903c0c2b17f05c116a", 65 | ) 66 | native.bind( 67 | name = "junit", 68 | actual = "@junit_artifact//jar", 69 | ) 70 | 71 | jvm_maven_import_external( 72 | name = "spock_artifact", 73 | artifact = "org.spockframework:spock-core:1.3-groovy-2.5", 74 | server_urls = ["https://mirror.bazel.build/repo1.maven.org/maven2"], 75 | licenses = ["notice"], 76 | artifact_sha256 = "4e5c788ce5bac0bda41cd066485ce84ab50e3182d81a6789b82a3e265cd85f90", 77 | ) 78 | native.bind( 79 | name = "spock", 80 | actual = "@spock_artifact//jar", 81 | ) 82 | --------------------------------------------------------------------------------