feat: dynamically determine protobuf version in build.gradle#1753
feat: dynamically determine protobuf version in build.gradle#1753JoeWang1127 merged 15 commits intomainfrom
Conversation
|
Can you add how you tested this in the pull request description? |
suztomo
left a comment
There was a problem hiding this comment.
Would you check whether the protobuf version line canbe removed?
gax-java/dependencies.properties
Outdated
| # Gradle build depends on prebuilt maven artifacts, while Bazel build depends on Bazel workspaces | ||
| # with the sources. | ||
| version.com_google_protobuf=3.23.2 | ||
| version.com_google_protobuf=3.21.12 |
There was a problem hiding this comment.
This line can't be removed because
depends on the key to be existed.There was a problem hiding this comment.
Of course the next question is the purpose of that line. Who calls com_google_api_gax_java_repositories()?
There was a problem hiding this comment.
com_google_api_gax_java_repositories() is called from googleapis/WORKSPACE and gax-java/WORKSPACE.
The protobuf version can be passed from googleapis when building client libraries. However, when running showcase tests, it will create a cycle in WORKSPACE if this line (version.com_google_protobuf=3.21.12) is removed.
Please see #1753 (comment)
There was a problem hiding this comment.
Add source code comment. It's used for showcase testing. Not for the generated Gradle file in googleapis project any more.
gax-java/repository_rules.bzl
Outdated
| # the version of protobuf defined in googleapis is higher than protobuf | ||
| # defined in gax-java/dependencies.properties, use this replacement to | ||
| # sync the two versions. | ||
| props_as_map["version.com_google_protobuf"] = PROTOBUF_JAVA_VERSION |
There was a problem hiding this comment.
Inject a key-value pair here, rather than in rules_java_gapic/java_gapic_pkg.bzl.
By doing this, we can remove protobuf version in gax-java/dependencies.properties
There was a problem hiding this comment.
This creates a cycle in gax-java/WORKSPACE:
(18:15:51) ERROR: Failed to load Starlark extension '@com_google_protobuf//:protobuf_version.bzl'.
Cycle in the workspace file detected. This indicates that a repository is used prior to being defined.
The following chain of repository dependencies lead to the missing definition.
- @com_google_protobuf
This could either mean you have to add the '@com_google_protobuf' repository with a statement like `http_archive` in your WORKSPACE file (note that transitive dependencies are not added automatically), or move an existing definition earlier in your WORKSPACE file.
Full log: https://github.com/googleapis/sdk-platform-java/actions/runs/5203236910/jobs/9385816289?pr=1753
This reverts commit 22d3d0c.
rules_java_gapic/java_gapic_pkg.bzl
Outdated
| return wrappedProperties | ||
|
|
||
| _PROPERTIES = _wrapPropertyNamesInBraces(PROPERTIES) | ||
| _PROPERTIES = _wrapPropertyNamesInBraces(PROPERTIES | _syncVersionWithGoogleapis()) |
There was a problem hiding this comment.
| _PROPERTIES = _wrapPropertyNamesInBraces(PROPERTIES | _syncVersionWithGoogleapis()) | |
| # Before this replacement, there is a problem (e.g., b/284292352) when ... | |
| PROPERTIES["version.com_google_protobuf"] = PROTOBUF_JAVA_VERSION | |
| _PROPERTIES = _wrapPropertyNamesInBraces(PROPERTIES) |
There was a problem hiding this comment.
This actually won't work as it will violate mutability rule.
ERROR: Traceback (most recent call last):
File "/private/var/tmp/_bazel_joewa/b6b64da05090260654456c80e641ce7c/external/gapic_generator_java/rules_java_gapic/java_gapic_pkg.bzl", line 28, column 43, in <toplevel>
PROPERTIES["version.com_google_protobuf"] = PROTOBUF_JAVA_VERSION
Error: trying to mutate a frozen dict value
There was a problem hiding this comment.
Nice learning. Then create a copy or operate on _PROPERTIES. The latter needs to tweak the key with braces.
| # the version of protobuf defined in googleapis is higher than protobuf | ||
| # defined in gax-java/dependencies.properties, use this replacement to | ||
| # sync the two versions. | ||
| SYNCED_PROPERTIES = PROPERTIES | {"version.com_google_protobuf": PROTOBUF_JAVA_VERSION} |
There was a problem hiding this comment.
@suztomo is this the idea of "making a copy"?
There was a problem hiding this comment.
This is better than what I was thinking with "dict.copy()".
rules_java_gapic/java_gapic_pkg.bzl
Outdated
| return wrappedProperties | ||
|
|
||
| _PROPERTIES = _wrapPropertyNamesInBraces(PROPERTIES) | ||
| # Before this replacement, there is a problem (e.g., b/284292352) when |
There was a problem hiding this comment.
| # Before this replacement, there is a problem (e.g., b/284292352) when | |
| # Before this replacement, there was a problem (e.g., b/284292352) when |
| # with the sources. | ||
| # The protobuf version is only used by showcase tests, not used by gradle files | ||
| # in generated, self-service clients (from googleapis project). | ||
| version.com_google_protobuf=3.23.2 |
There was a problem hiding this comment.
Is this used by showcase? I think the protobuf runtime version in Showcase module extends from gapic-generator-java-parent-pom
There was a problem hiding this comment.
Correct me if I'm wrong.
Looking at the ci error log, showcase golden tests eventually invoke bazelisk run //showcase:verify_gapic.
bazelisk run //showcase:verify_gapic will fail if version.com_google_protobuf=3.23.2 is removed from dependencies.properties.
There was a problem hiding this comment.
I see, I didn't notice that we are making sure showcase modules are compilable right after generation, they are still verified with the generated gradle files though.
gax-java/dependencies.properties
Outdated
| # The protobuf version is only used by showcase tests, not used by gradle files | ||
| # in generated, self-service clients (from googleapis project). |
There was a problem hiding this comment.
| # The protobuf version is only used by showcase tests, not used by gradle files | |
| # in generated, self-service clients (from googleapis project). | |
| # The protobuf version is only used for generating gradle files for showcase module, | |
| # not for self-service clients (from googleapis project). |
|
[gapic-generator-java-root] Kudos, SonarCloud Quality Gate passed! |
|
[java_showcase_integration_tests] Kudos, SonarCloud Quality Gate passed! |
|
[java_showcase_unit_tests] Kudos, SonarCloud Quality Gate passed! |








Fixes #1757.
Steps to verify this PR:
google-maps-fleetengine./path/sdkplatform-java.googleapisrepository, runbazelisk buildto build the client library withgapic-generator-javaandgax-javareplaced with local repository.For example,
bazelisk build //google/maps/fleetengine/v1:google-maps-fleetengine-v1-java --override_repository=gapic_generator_java=/path/sdk-platform-java/ --override_repository=com_google_api_gax_java=/path/sdk-platform-java/gax-java/googleapisrepository, unzip the generated tar file togoogleapisroot directory.For example,
tar -xf bazel-bin/google/maps/fleetengine/v1/google-maps-fleetengine-v1-java.tar.gzcom.google.protobuf:protobuf-javainproto-*/build.gradleand make sure the version is the same as protobuf version defined inWORKSPACEingooleapis.google-maps-fleetengine-v1-java/), and run./gradlew build.