Skip to content

Commit

Permalink
Split maven dependencies into dev vs local (#20549) (#20558)
Browse files Browse the repository at this point in the history
Closes #20549

COPYBARA_INTEGRATE_REVIEW=#20549 from protocolbuffers:maven-split a8b30b4
PiperOrigin-RevId: 733361548
  • Loading branch information
mkruskal-google authored Mar 4, 2025
1 parent 6059cb7 commit a5c906a
Show file tree
Hide file tree
Showing 10 changed files with 1,462 additions and 1,175 deletions.
11 changes: 11 additions & 0 deletions .github/workflows/test_bazel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,17 @@ jobs:
with:
ref: ${{ inputs.safe-checkout }}

# rules_jvm_external doesn't support Java 8, which is the default version
# on some github runners. When this is selected, it results in some
# opaque errors about coursier (see
# https://github.com/bazel-contrib/rules_jvm_external/issues/1337).
- name: Pin to Java 11
uses: actions/setup-java@3a4f6e1af504cf6a31855fa899c6aa5355ba6c12 # v4.7.0
if: ${{ !matrix.continuous-only || inputs.continuous-run }}
with:
distribution: 'temurin'
java-version: '11'

- name: Windows startup flags
if: ${{ runner.os == 'Windows' && (!matrix.continuous-only || inputs.continuous-run) }}
working-directory: examples
Expand Down
28 changes: 20 additions & 8 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -80,16 +80,11 @@ pip = use_extension("@rules_python//python/extensions:pip.bzl", "pip", dev_depen

use_repo(pip, "protobuf_pip_deps")

maven = use_extension("@rules_jvm_external//:extensions.bzl", "maven", dev_dependency = True)
maven.install(
protobuf_maven = use_extension("@rules_jvm_external//:extensions.bzl", "maven", dev_dependency = True)
protobuf_maven.install(
name = "protobuf_maven",
artifacts = [
"com.google.caliper:caliper:1.0-beta-3",
"com.google.code.findbugs:jsr305:3.0.2",
"com.google.code.gson:gson:2.8.9",
"com.google.errorprone:error_prone_annotations:2.5.1",
"com.google.j2objc:j2objc-annotations:2.8",
"com.google.guava:guava:32.0.1-jre",
"com.google.guava:guava-testlib:32.0.1-jre",
"com.google.testparameterinjector:test-parameter-injector:1.18",
"com.google.truth:truth:1.1.2",
Expand All @@ -103,7 +98,24 @@ maven.install(
"https://repo.maven.apache.org/maven2",
],
)
use_repo(maven, "protobuf_maven")
use_repo(protobuf_maven, "protobuf_maven")

maven = use_extension("@rules_jvm_external//:extensions.bzl", "maven")
maven.install(
name = "maven",
artifacts = [
"com.google.code.findbugs:jsr305:3.0.2",
"com.google.code.gson:gson:2.8.9",
"com.google.errorprone:error_prone_annotations:2.5.1",
"com.google.j2objc:j2objc-annotations:2.8",
"com.google.guava:guava:32.0.1-jre",
],
repositories = [
"https://repo1.maven.org/maven2",
"https://repo.maven.apache.org/maven2",
],
)
use_repo(maven, "maven")

# Development dependencies
bazel_dep(name = "googletest", version = "1.14.0", dev_dependency = True)
Expand Down
30 changes: 27 additions & 3 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ rules_jvm_external_setup()
load("@rules_jvm_external//:defs.bzl", "maven_install")

maven_install(
name = "protobuf_maven",
name = "maven",
artifacts = PROTOBUF_MAVEN_ARTIFACTS,
# For updating instructions, see:
# https://github.com/bazelbuild/rules_jvm_external#updating-maven_installjson
Expand All @@ -76,10 +76,34 @@ maven_install(
],
)

load("@protobuf_maven//:defs.bzl", "pinned_maven_install")

load("@maven//:defs.bzl", "pinned_maven_install")
pinned_maven_install()

maven_install(
name = "protobuf_maven",
artifacts = [
"com.google.caliper:caliper:1.0-beta-3",
"com.google.guava:guava-testlib:32.0.1-jre",
"com.google.testparameterinjector:test-parameter-injector:1.18",
"com.google.truth:truth:1.1.2",
"junit:junit:4.13.2",
"org.mockito:mockito-core:4.3.1",
"biz.aQute.bnd:biz.aQute.bndlib:6.4.0",
"info.picocli:picocli:4.6.3",
],
# For updating instructions, see:
# https://github.com/bazelbuild/rules_jvm_external#updating-maven_installjson
maven_install_json = "//:maven_dev_install.json",
repositories = [
"https://repo1.maven.org/maven2",
"https://repo.maven.apache.org/maven2",
],
)

load("@protobuf_maven//:defs.bzl", pinned_protobuf_maven_install = "pinned_maven_install")
pinned_protobuf_maven_install()


# For `cc_proto_blacklist_test` and `build_test`.
load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace")

Expand Down
5 changes: 3 additions & 2 deletions examples/AddPerson.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// See README.md for information and build instructions.

import com.example.tutorial.protos.AddressBook;
import com.example.tutorial.protos.Person;
import com.google.protobuf.util.Timestamps;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintStream;

class AddPerson {
Expand Down Expand Up @@ -51,6 +51,7 @@ static Person PromptForAddress(BufferedReader stdin,
}

person.addPhones(phoneNumber);
person.setLastUpdated(Timestamps.now());
}

return person.build();
Expand Down
10 changes: 8 additions & 2 deletions examples/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,10 @@ java_binary(
name = "add_person_java",
srcs = ["AddPerson.java"],
main_class = "AddPerson",
deps = [":addressbook_java_proto"],
deps = [
":addressbook_java_proto",
"@com_google_protobuf//java/util",
],
)

java_binary(
Expand Down Expand Up @@ -112,7 +115,10 @@ java_binary(
name = "add_person_java_lite",
srcs = ["AddPerson.java"],
main_class = "AddPerson",
deps = [":addressbook_java_lite_proto"],
deps = [
":addressbook_java_lite_proto",
"@com_google_protobuf//java/util",
],
)

java_binary(
Expand Down
18 changes: 17 additions & 1 deletion examples/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ http_archive(
],
)

load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps")
load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps", "PROTOBUF_MAVEN_ARTIFACTS")

protobuf_deps()

Expand All @@ -59,3 +59,19 @@ load("@rules_cc//cc:repositories.bzl", "rules_cc_dependencies", "rules_cc_toolch
rules_cc_dependencies()

rules_cc_toolchains()

load("@rules_jvm_external//:repositories.bzl", "rules_jvm_external_deps")
rules_jvm_external_deps()

load("@rules_jvm_external//:setup.bzl", "rules_jvm_external_setup")
rules_jvm_external_setup()

load("@rules_jvm_external//:defs.bzl", "maven_install")
maven_install(
name = "maven",
artifacts = PROTOBUF_MAVEN_ARTIFACTS,
repositories = [
"https://repo1.maven.org/maven2",
"https://repo.maven.apache.org/maven2",
],
)
10 changes: 5 additions & 5 deletions java/util/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ java_library(
visibility = ["//visibility:public"],
deps = [
"//java/core",
"@protobuf_maven//:com_google_code_findbugs_jsr305",
"@protobuf_maven//:com_google_code_gson_gson",
"@protobuf_maven//:com_google_errorprone_error_prone_annotations",
"@protobuf_maven//:com_google_guava_guava",
"@protobuf_maven//:com_google_j2objc_j2objc_annotations",
"@maven//:com_google_code_findbugs_jsr305",
"@maven//:com_google_code_gson_gson",
"@maven//:com_google_errorprone_error_prone_annotations",
"@maven//:com_google_guava_guava",
"@maven//:com_google_j2objc_j2objc_annotations",
],
)

Expand Down
Loading

0 comments on commit a5c906a

Please sign in to comment.