Skip to content

Commit 99d2490

Browse files
authored
fix: don't mix coursier-resolved classpath with individual http_jar (#337)
This is a recipe for confusion if the Maven dependencies bring a different protobuf-java version, they should be constraint-solved together. Instead, demonstrate http_jar with a different tool where we are guaranteed it's the only thing on the classpath.
1 parent 5c5cb8b commit 99d2490

File tree

6 files changed

+96
-130
lines changed

6 files changed

+96
-130
lines changed

MODULE.bazel

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ bazel_dep(name = "toolchains_protoc", version = "0.3.1")
3939
http_jar = use_repo_rule("@bazel_tools//tools/build_defs/repo:http.bzl", "http_jar")
4040

4141
http_jar(
42-
name = "protobuf-java",
43-
integrity = "sha256-eYx59sn8aFnMdqpUdCKKrSUIIUOOEATa00iA1TqnRfk=",
44-
urls = ["https://repo1.maven.org/maven2/com/google/protobuf/protobuf-java/4.27.1/protobuf-java-4.27.1.jar"],
42+
name = "google-java-format",
43+
sha256 = "33068bbbdce1099982ec1171f5e202898eb35f2919cf486141e439fc6e3a4203",
44+
url = "https://github.com/google/google-java-format/releases/download/v1.17.0/google-java-format-1.17.0-all-deps.jar",
4545
)
4646

4747
#########################
@@ -120,7 +120,10 @@ use_repo(pip, "pip")
120120

121121
maven = use_extension("@rules_jvm_external//:extensions.bzl", "maven")
122122
maven.install(
123-
artifacts = ["io.grpc:grpc-all:1.51.1"],
123+
artifacts = [
124+
"com.google.protobuf:protobuf-java:4.27.1",
125+
"io.grpc:grpc-all:1.51.1",
126+
],
124127
lock_file = "//:maven_install.json",
125128
)
126129
use_repo(

MODULE.bazel.lock

Lines changed: 26 additions & 24 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.bazel.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,15 @@ If the package is not already a dependency of the project, you'll have to do som
9999
% bazel configure
100100
```
101101

102+
## Working with Java maven dependencies
103+
104+
Maven coordinates for third-party packages live in the `MODULE.bazel` file.
105+
106+
After changing them, run `bazel run @unpinned_maven//:pin` to update the `maven_install.json` file.
107+
This file is used by `rules_jvm_external` to fetch packages.
108+
109+
Then use the `artifact("some.org:coordinate")` helper to resolve a label to the resulting `java_library` targets.
110+
102111
## Stamping release builds
103112

104113
Stamping produces non-deterministic outputs by including information such as a version number or commit hash.

0 commit comments

Comments
 (0)