Skip to content

Commit

Permalink
Fix and disallow Java classpath collisions in Bazel
Browse files Browse the repository at this point in the history
This relies on the recently added oneversion support in rules_java.
  • Loading branch information
fmeum committed Sep 11, 2024
1 parent aed6a40 commit 525444b
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 117 deletions.
4 changes: 4 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ build --java_language_version=21
build --tool_java_language_version=21
build --tool_java_runtime_version=21

# Fail if a production classpath contains different versions of the same class
build --experimental_one_version_enforcement=ERROR
build --noone_version_enforcement_on_java_tests

# Fail if a glob doesn't match anything (https://github.com/bazelbuild/bazel/issues/8195)
common --incompatible_disallow_empty_glob

Expand Down
4 changes: 3 additions & 1 deletion MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ maven.install(
"com.google.auto.value:auto-value-annotations:1.11.0",
"com.google.code.findbugs:jsr305:3.0.2",
"com.google.code.gson:gson:2.10.1",
"com.google.code.java-allocation-instrumenter:java-allocation-instrumenter:3.3.0",
"com.google.code.java-allocation-instrumenter:java-allocation-instrumenter:3.3.4",
"com.google.errorprone:error_prone_annotation:2.23.0",
"com.google.errorprone:error_prone_annotations:2.23.0",
"com.google.errorprone:error_prone_check_api:2.23.0",
Expand Down Expand Up @@ -200,6 +200,8 @@ maven.install(
# We build protobuf Java library from source, exclude protobuf jars to be safe.
"com.google.protobuf:protobuf-java",
"com.google.protobuf:protobuf-javalite",
# Provided by @googleapis.
"com.google.api.grpc:proto-google-common-protos",
],
# Don't forget to change this to back to True before submitting your change.
fail_if_repin_required = True,
Expand Down
47 changes: 19 additions & 28 deletions MODULE.bazel.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

71 changes: 14 additions & 57 deletions maven_install.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"__AUTOGENERATED_FILE_DO_NOT_MODIFY_THIS_FILE_MANUALLY": "THERE_IS_NO_DATA_ONLY_ZUUL",
"__INPUT_ARTIFACTS_HASH": 41510960,
"__RESOLVED_ARTIFACTS_HASH": -909692052,
"__INPUT_ARTIFACTS_HASH": 1727296549,
"__RESOLVED_ARTIFACTS_HASH": 71572728,
"conflict_resolution": {
"com.google.code.gson:gson:2.8.9": "com.google.code.gson:gson:2.10.1",
"com.google.errorprone:error_prone_annotations:2.23.0": "com.google.errorprone:error_prone_annotations:2.28.0",
Expand Down Expand Up @@ -65,12 +65,6 @@
},
"version": "1.35.2"
},
"com.google.api.grpc:proto-google-common-protos": {
"shasums": {
"jar": "0d830380ec66bd7e25eee63aa0a5a08578e46ad187fb72d99b44d9ba22827f91"
},
"version": "2.9.0"
},
"com.google.auth:google-auth-library-credentials": {
"shasums": {
"jar": "153fa3cdc153ac3ee25649e8037aeda4438256153d35acf3c27e83e4ee6165a4"
Expand Down Expand Up @@ -127,9 +121,9 @@
},
"com.google.code.java-allocation-instrumenter:java-allocation-instrumenter": {
"shasums": {
"jar": "1ef5535a8bd41cf3072469f381b9ee6ab28275311a7499f53d6e52adf976fef0"
"jar": "44f8cddec129520b2532fa9ff25f9572d7566307d660635ba32bf409f06ae336"
},
"version": "3.3.0"
"version": "3.3.4"
},
"com.google.errorprone:error_prone_annotation": {
"shasums": {
Expand Down Expand Up @@ -829,15 +823,6 @@
"com.google.auto:auto-common": [
"com.google.guava:guava"
],
"com.google.code.java-allocation-instrumenter:java-allocation-instrumenter": [
"com.google.guava:guava",
"javax.annotation:javax.annotation-api",
"org.ow2.asm:asm",
"org.ow2.asm:asm-analysis",
"org.ow2.asm:asm-commons",
"org.ow2.asm:asm-tree",
"org.ow2.asm:asm-util"
],
"com.google.errorprone:error_prone_annotation": [
"com.google.guava:guava"
],
Expand Down Expand Up @@ -1026,7 +1011,6 @@
"io.perfmark:perfmark-api"
],
"io.grpc:grpc-protobuf": [
"com.google.api.grpc:proto-google-common-protos",
"com.google.code.findbugs:jsr305",
"com.google.guava:guava",
"io.grpc:grpc-api",
Expand Down Expand Up @@ -1328,18 +1312,6 @@
"com.google.api-client:google-api-client-gson": [
"com.google.api.client.googleapis.notifications.json.gson"
],
"com.google.api.grpc:proto-google-common-protos": [
"com.google.api",
"com.google.cloud",
"com.google.cloud.audit",
"com.google.cloud.location",
"com.google.geo.type",
"com.google.logging.type",
"com.google.longrunning",
"com.google.rpc",
"com.google.rpc.context",
"com.google.type"
],
"com.google.auth:google-auth-library-credentials": [
"com.google.auth"
],
Expand Down Expand Up @@ -1422,30 +1394,16 @@
"com.google.monitoring.runtime.instrumentation.asm.commons",
"com.google.monitoring.runtime.instrumentation.asm.signature",
"com.google.monitoring.runtime.instrumentation.asm.tree",
"com.google.monitoring.runtime.instrumentation.asm.tree.analysis",
"com.google.monitoring.runtime.instrumentation.asm.util",
"com.google.monitoring.runtime.instrumentation.checker.nullness.compatqual",
"com.google.monitoring.runtime.instrumentation.common.annotations",
"com.google.monitoring.runtime.instrumentation.common.base",
"com.google.monitoring.runtime.instrumentation.common.base.internal",
"com.google.monitoring.runtime.instrumentation.common.cache",
"com.google.monitoring.runtime.instrumentation.common.collect",
"com.google.monitoring.runtime.instrumentation.common.escape",
"com.google.monitoring.runtime.instrumentation.common.eventbus",
"com.google.monitoring.runtime.instrumentation.common.graph",
"com.google.monitoring.runtime.instrumentation.common.hash",
"com.google.monitoring.runtime.instrumentation.common.html",
"com.google.monitoring.runtime.instrumentation.common.io",
"com.google.monitoring.runtime.instrumentation.common.math",
"com.google.monitoring.runtime.instrumentation.common.net",
"com.google.monitoring.runtime.instrumentation.common.primitives",
"com.google.monitoring.runtime.instrumentation.common.reflect",
"com.google.monitoring.runtime.instrumentation.common.util.concurrent",
"com.google.monitoring.runtime.instrumentation.common.xml",
"com.google.monitoring.runtime.instrumentation.errorprone.annotations",
"com.google.monitoring.runtime.instrumentation.errorprone.annotations.concurrent",
"com.google.monitoring.runtime.instrumentation.j2objc.annotations",
"com.google.thirdparty.publicsuffix"
"com.google.monitoring.runtime.instrumentation.common.com.google.common.annotations",
"com.google.monitoring.runtime.instrumentation.common.com.google.common.base",
"com.google.monitoring.runtime.instrumentation.common.com.google.common.cache",
"com.google.monitoring.runtime.instrumentation.common.com.google.common.collect",
"com.google.monitoring.runtime.instrumentation.common.com.google.common.math",
"com.google.monitoring.runtime.instrumentation.common.com.google.common.primitives",
"com.google.monitoring.runtime.instrumentation.common.com.google.common.util.concurrent",
"com.google.monitoring.runtime.instrumentation.common.com.google.common.util.concurrent.internal",
"javax.annotation",
"javax.annotation.security"
],
"com.google.errorprone:error_prone_annotation": [
"com.google.errorprone"
Expand Down Expand Up @@ -2733,7 +2691,6 @@
"com.google.android:annotations",
"com.google.api-client:google-api-client",
"com.google.api-client:google-api-client-gson",
"com.google.api.grpc:proto-google-common-protos",
"com.google.auth:google-auth-library-credentials",
"com.google.auth:google-auth-library-oauth2-http",
"com.google.auto.service:auto-service",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,6 @@ bootstrap_java_library(
"//third_party:jsr305-jars",
"//third_party/java/jacoco:core-jars",
"//third_party/grpc-java:bootstrap-grpc-jars",
"//third_party:tomcat_annotations_api-jars",
],
neverlink_jars = ["//third_party:auto_value-jars"],
tags = ["manual"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ java_library(
"//src/main/protobuf:deps_java_proto",
"//third_party:auto_value",
"//third_party:guava",
"//third_party:tomcat_annotations_api",
],
)

Expand Down
17 changes: 0 additions & 17 deletions third_party/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@ java_plugin(
":auto_value_lib",
":guava",
":jsr305",
":tomcat_annotations_api",
],
)

Expand Down Expand Up @@ -201,7 +200,6 @@ java_plugin(
":auto_service_lib",
":auto_value_lib",
":guava",
":tomcat_annotations_api",
],
)

Expand All @@ -215,7 +213,6 @@ java_plugin(
":auto_service_lib",
":auto_value_lib",
":guava",
":tomcat_annotations_api",
],
)

Expand All @@ -229,7 +226,6 @@ java_plugin(
":auto_service_lib",
":auto_value_lib",
":guava",
":tomcat_annotations_api",
],
)

Expand All @@ -253,7 +249,6 @@ java_library(
],
exports = [
":auto_value_api",
":tomcat_annotations_api",
"@maven//:com_ryanharter_auto_value_auto_value_gson_runtime",
],
)
Expand Down Expand Up @@ -577,18 +572,6 @@ distrib_java_import(
}),
)

alias(
name = "tomcat_annotations_api",
actual = "@maven//:org_apache_tomcat_tomcat_annotations_api",
)

# For bootstrapping JavaBuilder
distrib_jar_filegroup(
name = "tomcat_annotations_api-jars",
srcs = ["@maven//:org_apache_tomcat_tomcat_annotations_api_file"],
enable_distributions = ["debian"],
)

alias(
name = "java-diff-utils",
actual = "@maven//:io_github_java_diff_utils_java_diff_utils",
Expand Down
12 changes: 0 additions & 12 deletions tools/distributions/debian/debian_java.BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,6 @@ java_import(
jars = ["java/gson.jar"],
)

# libtomcat9-java
java_import(
name = "tomcat_annotations_api",
jars = ["java/tomcat9-annotations-api.jar"],
)

# For bootstrapping java toolcahin
filegroup(
name = "tomcat_annotations_api-jars",
srcs = ["java/tomcat9-annotations-api.jar"],
)

# libjava-allocation-instrumenter-java
java_import(
name = "allocation_instrumenter",
Expand Down

0 comments on commit 525444b

Please sign in to comment.