Skip to content

Commit 1fc8cb2

Browse files
authored
Better Bazel jar -> Maven example (#190)
1 parent c18f67c commit 1fc8cb2

File tree

2 files changed

+11
-27
lines changed

2 files changed

+11
-27
lines changed

docs/bazel_maven_workflow.md

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -47,35 +47,11 @@ java_library(
4747

4848
## Build jars with Bazel and use them in a Maven project
4949

50-
Similar to above, we can build jars using Bazel, so that they can be used in Maven projects. See below for detailed steps.
50+
Similar to above, we can build jars using Bazel, so that they can be used in Maven projects:
5151

5252
1. Make code changes to the library which you want to release a jar for.
5353
1. Build the library by running `bazel build path/to/library/...`.
5454
1. Run `bazel run @pomgen//maven -- -a pomgen,install -l path/to/library` to generate poms and install the jars to `~/.m2/repository`.
5555
1. Update the pom.xml in the consuming Maven project to use the right jar version
5656

57-
58-
### Example
59-
60-
Make some code changes in `examples/hello-world/healthyfoods/fruit-api`.
61-
62-
Run bazel build.
63-
```
64-
bazel build //examples/hello-world/healthyfoods/...
65-
```
66-
67-
Generate pom(s) and install artifacts into `~/.m2/repository`:
68-
```
69-
bazel run @pomgen//maven -- -a pomgen,install -l examples/hello-world/healthyfoods
70-
```
71-
72-
Then, update the pom.xml of the consuming Maven project.
73-
```
74-
<dependency>
75-
<groupId>com.pomgen.example</groupId>
76-
<artifactId>fruit-api</artifactId>
77-
<version>1.0.0-SNAPSHOT</version>
78-
</dependency>
79-
```
80-
81-
Now you can compile your Maven project, it will use the latest jars produced by Bazel.
57+
See [this example](../examples/hello-world#installing-maven-artifacts-into-the-local-maven-repository) for more information.

examples/hello-world/README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ The Maven Artifacts generated by pomgen can be installed into `~/.m2/repository`
8484
bazel run @pomgen//maven -- -a install -l examples/hello-world/juicer
8585
```
8686

87+
Note that before running `-a install`, pom.xml files must have been generated: `-a pomgen` must have run.
88+
8789
If you see this type of error:
8890

8991
```
@@ -94,8 +96,14 @@ This error means that pomgen did not find the jar file for the juicer module - t
9496
- Run `bazel build examples/hello-world/...`
9597
- If there are many upstream libraries in a large repository, it may be helpful to ask pomgen to build all upstream libraries - use the `build` action: `bazel run @pomgen//maven -- -a build -l examples/hello-world/juicer`
9698

99+
Finally, note that `-a` can take multiple actions, so the above can also be run like this:
100+
101+
```
102+
bazel run @pomgen//maven -- -a pomgen,build,install -l examples/hello-world/juicer
103+
```
104+
97105

98-
### Using pomgen libraries in a Maven projects
106+
### Referencing Bazel-built jars in a Maven projects
99107

100108
Once the `install` action ran successfully for `examples/hello-world/juicer`, you can use the `juicer` artifact in a Maven project. Try this pom.xml:
101109

0 commit comments

Comments
 (0)