Commit af52834
authored
Adding Scala and multiple POM files support. (#217)
## What is the goal of this PR?
Fixing four issues:
1. I'm also using Scala here, which is almost identical in deployment to Java. However, using [scala_library](https://github.com/bazelbuild/rules_scala/blob/master/docs/scala_library.md) with `assemble_maven` doesn't work.
2. The POM file name is hard-coded (`pom.xml`). Because we use both Scala and Java in the same BUILD file, the file was getting overwrite. #215
3. Targets that have only the `files` attribute failed to run because the provider return `srcjar` when there's isn't any defined. #214
4. `target_coordinates` is hard-coded to `[0]`, and it's not working on all cases.
There's another thing to consider here it seems. When using exports, I had problem with:
target_string = target[JavaLibInfo].target_coordinates.to_list()[-1]
The first element in the array was the export, and not the root target itself. It seems like [-1] worked better on couple of scenario I tested it again, but it's probably better to write a logic to pick the right target instead of guessing.
## What are the changes implemented in this PR?
- `pom.xml` will now be named based on the target name. So if my `assemble_maven` target name is `hello_world`, the pom is called `hello_world_pom.xml`.
- Side effect of the above is that now `deploy_maven` requires a target (it was optional). The reason for that is because `pom.xml` was hard-coded into `deploy_maven`. Now the unique pom file name is being grabbed from the Target directly.
- I changed the if condition that extracts jars and srcjars. First I'm checking the target has `files` attribute in it. If it does, I'm checking that there's files in `files`, and lastly I check the first file has JAR file in it (like you previously did). I also modified the way srcjars are being picked. I'm looking for `-src.jar` ending exclusively (the previous code was picking the first file in the list, and it wasn't the right srcjar using `scala_library` targets).
- Srcjar is not available on all jars. In case there is no srcjar, the Provider no longer return it (it used to fail here).
- When using exports, the first item in the `target_coordinates` array is not the root target (`target_string = target[JavaLibInfo].target_coordinates.to_list()[0]`. It seems like [-1] worked better on couple of scenario I tested it again (as the root target was always the last in the list), but it's probably better to write a logic to pick the right target instead of guessing.
## Notes
I tested it on my Bazel project. I didn't find any tests to run the code changes on, so it's probably a good idea to try to run it on your Bazel projects to make sure it didn't break anything I wasn't aware of.
Thanks.1 parent 2b1cace commit af52834
1 file changed
+25
-13
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
164 | 164 | | |
165 | 165 | | |
166 | 166 | | |
167 | | - | |
| 167 | + | |
168 | 168 | | |
169 | | - | |
| 169 | + | |
170 | 170 | | |
171 | 171 | | |
172 | 172 | | |
| |||
259 | 259 | | |
260 | 260 | | |
261 | 261 | | |
262 | | - | |
| 262 | + | |
263 | 263 | | |
264 | 264 | | |
265 | 265 | | |
266 | 266 | | |
267 | 267 | | |
268 | 268 | | |
269 | | - | |
270 | | - | |
271 | | - | |
272 | | - | |
273 | | - | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
274 | 279 | | |
275 | 280 | | |
276 | 281 | | |
| |||
283 | 288 | | |
284 | 289 | | |
285 | 290 | | |
286 | | - | |
287 | | - | |
288 | | - | |
289 | | - | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
290 | 301 | | |
291 | 302 | | |
292 | 303 | | |
| |||
366 | 377 | | |
367 | 378 | | |
368 | 379 | | |
369 | | - | |
| 380 | + | |
370 | 381 | | |
371 | 382 | | |
372 | 383 | | |
| |||
399 | 410 | | |
400 | 411 | | |
401 | 412 | | |
| 413 | + | |
402 | 414 | | |
403 | 415 | | |
404 | 416 | | |
| |||
0 commit comments