Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

How can I dynamically share and update Maven artifact versions across multiple MODULE.bazel files using Bzlmod?#27386

Answeredbyshs96c
abdi810103 asked this question inQ&A
Discussion options

🧩 Title:

How can I dynamically share and update Maven artifact versions across multiple MODULE.bazel files using Bzlmod?


📝 Description:

Hi Bazel team 👋

I’m currently working in a large Bazel monorepo where we useBzlmod andrules_jvm_external for dependency management.
We want to have asingle source of truth for dependency versions (e.g.,FIP_VERSION,SWAGGER_VERSION, etc.) that can be shared across multiple.MODULE.bazel files — for example:

/MODULE.bazel/third-party-deps/main-maven.MODULE.bazel

Both define Maven repositories and should stay in sync automatically.


💡 What we’ve tried so far

  1. We created a centralversions.json file containing all artifact versions.

  2. We implemented amodule extension that reads this JSON and prints the values:

    def_maven_versions_ext_impl(module_ctx):data=json.decode(module_ctx.read(module_ctx.path(module_ctx.attr.json_file)))print("✅ Loaded versions:",data)

    That part works — the extension can read the JSON and print dynamic versions.

  3. We tried to reuse those versions in another.MODULE.bazel file by loading them like this:

    use_extension("//third-party-deps:maven_versions_ext.bzl","maven_versions_ext")maven_versions_ext.maven_versions(json_file="//:versions.json")use_repo(maven_versions_ext,"versions_repo")load("@versions_repo//:versions.bzl","version_json")

    However, that fails becauserepositories generated by a module extension are not visible during the same module evaluation phase.
    (We get:name 'versions_repo' is not defined or similar errors.)

  4. We also tried variants using:

    • module_ctx.generate_repo()
    • repository_rule withuse_repo_rule()
    • Directly referencing JSON insidemaven.install(artifacts = "//:artifacts.json")

    But Bzlmod’s evaluation model prevents dynamic file loading during module evaluation.


❓ The question

Is there an officially supported or recommended way inBzlmod to:

  • Define shared version data (e.g.,versions.json) once,
  • Have it dynamically read and exported by a module extension,
  • And make it accessible acrossmultiple MODULE.bazel files in the same monorepo?

Essentially:

How can multiple module files use the same dynamically generated repository or version constantswithout duplicating logic or hardcoding versions?


⚙️ Context

  • Bazel version:7.x

  • rules_jvm_external:6.5

  • rules_spring / rules_kotlin / aspect_rules_js also used

  • The goal is to have something like this:

    # in MODULE.bazeluse_extension("//third-party-deps:maven_versions_ext.bzl","maven_versions_ext")maven_versions_ext.maven_versions(json_file="//:versions.json")use_repo(maven_versions_ext,"versions_repo")
    # in another MODULE.bazeluse_extension("//third-party-deps:maven_versions_ext.bzl","maven_versions_ext")use_repo(maven_versions_ext,"versions_repo")load("@versions_repo//:versions.bzl","version_json")

But Bazel currently doesn’t seem to allow reading a generated repo in another module file in the same evaluation phase.


💬 Expected outcome

A supported pattern (or documentation reference) forsharing dynamically generated data (like Maven versions) between multiple.MODULE.bazel files using module extensions — without duplicating constants or breaking Bazel’s module loading order.


Would this be possible through:

  • A new feature inmodule_ctx (e.g. exposing generated repos earlier)?
  • A recommended Bazel-native pattern for shared configuration between multiple module files?
  • Or is the only safe path to hardcode or script the version updates externally?

🙏 Thank you

Any guidance or official example on this kind of multi-MODULE shared state in Bzlmod would be greatly appreciated.
It would help a lot for large-scale monorepos managing dependency versions centrally.


Environment:

  • macOS / Linux
  • Bazel 7.x
  • Usingrules_jvm_external,rules_kotlin,rules_js,rules_spring, etc.

Would you like me to make it slightly shorter and more “GitHub issue” friendly (i.e. fewer explanations, more condensed)?
That way you can copy-paste it directly into a GitHub issue.

You must be logged in to vote

In the latestrules_jvm_external release, we added support for reading dependencies from aGradle version catalog. This can be accessed usingfrom_toml tag. That sounds like it'd be the right fit for this problem.

One property that this has is that there are many tools that understand the format of this file, and can do useful things like automatically update dependencies.

Replies: 3 comments 3 replies

Comment options

Given that .MODULE.bazel no longer supports load(), what is the recommended pattern in Bzlmod for:
Dynamically reading shared version data (e.g., from versions.json), and
Sharing it between multiple .MODULE.bazel files, so all modules can use the same artifact versions,
Without duplicating constants or managing them externally via scripts.

Specifically:

How can multiple module files reference the same dynamically generated repository (e.g., @versions_repo) or shared version constants, when Bazel’s module evaluation model prevents load() and same-phase repo access?

You must be logged in to vote
0 replies
Comment options

In the latestrules_jvm_external release, we added support for reading dependencies from aGradle version catalog. This can be accessed usingfrom_toml tag. That sounds like it'd be the right fit for this problem.

One property that this has is that there are many tools that understand the format of this file, and can do useful things like automatically update dependencies.

You must be logged in to vote
2 replies
@abdi810103
Comment options

Hi and thanks👋
I tried using the new from_toml feature you mentioned for rules_jvm_external.
I created a libs.versions.toml file in the repo root with the following:

[versions]
fip = "2025-10-10-1304-18404614297-1"
swagger = "2.2.27"

[libraries]

swagger-core        = { module = "io.swagger.core.v3:swagger-core", version.ref = "swagger" }swagger-models      = { module = "io.swagger.core.v3:swagger-models", version.ref = "swagger" }fip-api             = { module = "no.fremtind.fip.api:fip-api-jakarta", version.ref = "fip" }

Then in my MODULE.bazel file, I added:

maven = use_extension("@rules_jvm_external//:extensions.bzl", "maven")maven.from_toml(    name = "maven_deps",    libs_versions_toml = "//:libs.versions.toml",)

But when I run REPIN=1 bazel run @maven//:pin, I don’t see any of these versions or dependencies appearing in the generated maven_install.json file.

Am I missing a step — do I need to reference the maven_deps tag somehow inside maven.install() or use another attribute to make the TOML versions apply?

@abdi810103
Comment options

Thanks, it’s all working for me now! 🙌

Answer selected byabdi810103
Comment options

Wouldhttps://bazel.build/rules/lib/globals/module#include help with your use case?

You must be logged in to vote
1 reply
@abdi810103
Comment options

No, include is meant for importing another Bazel module file, not for this purpose.
That’s not what I’m looking for in this case.

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Category
Q&A
Labels
None yet
3 participants
@abdi810103@shs96c@meteorcloudy

[8]ページ先頭

©2009-2025 Movatter.jp