Code Monkey home page Code Monkey logo

Comments (5)

johnynek avatar johnynek commented on July 17, 2024

yeah, I don't think bazel will allow us to compose workspace.bzl loads in this way.

The way we do it at stripe is to merge the yaml files and then regenerate the workspace.bzl from there.

I added a merge command to deal with this case, sadly, I think it can create some errors on merge and not quite ready to use.

from bazel-deps.

ramtej avatar ramtej commented on July 17, 2024

Hello,
thank you for your answer.

I don't think bazel will allow us to compose workspace.bzl loads in this way.

Do you mean that conceptually this approach does not makes sense ? My intention was to introduce an "App" based approach following the microservice patterns (share nothing principle). That means that each xyz.app is self-contained and is executed in a docker/kubernetes environment. Further, it is a fully valid case where two apps are using the same maven artifact, but in different versions.

The way we do it at stripe is to merge the yaml files and then regenerate the workspace.bzl from there

Ok, means there is a kind of preprocessing step that parses the different yaml files, generates the "final.yaml" that is then used to generate the bazel 3rdparty dependencies. Hmm, see the point.

I would expect that there is a kind isolation/visibility pattern included in bazel where packages can manage they own dependency, e.g. @a_app//:jar/junit/junit.

Regards,
jj

from bazel-deps.

ramtej avatar ramtej commented on July 17, 2024

Hi,
I could solve the issue with support given by the bazel community. The simple trick is to verify if a rule (maven_jar) is already defined in the repository.

That means, the one can build two workspaces, e.g. ~/tmp/bazel-multiworkspace-sampler/profile$ bazel build @a_app//... @b_app//...
The load.bzl looks as follow:

if native.existing_rule(item["name"]) == None: 
    if sha != None:
      native.maven_jar(name = item["name"], artifact = item["artifact"], sha1 = sha)
    else:
      native.maven_jar(name = item["name"], artifact = item["artifact"])
    native.bind(name = item["bind"], actual = item["actual"])

See full sample at https://github.com/ramtej/bazel-multiworkspace-sampler

The issue is still, that two different maven_jar artifacts can have the same maven_jar rule name.
Evtl. the "bind": "jar/junit/junit" definition in the generated dependencies.bzl can contain the version and the maven_jar rule as well, e.g. "bind": "jar/junit/junit_4_12.

That means also that the BUILD files has to reference the version number :

java_test(
    name = "hello",
    srcs = ["TestHello.java"],
    test_class = "com.example.myproject.TestHello",
    deps = [
        "//src/main/java/com/example/myproject:hello-lib",
        "//external:jar/junit/junit_4_12",
    ],
)

alternatively the current workspace name can be used for binding e.g. "//external:a_app_jar/junit/junit",

Cheers,
jj

from bazel-deps.

johnynek avatar johnynek commented on July 17, 2024

this is a nice solution!

Thanks for sharing.

from bazel-deps.

johnynek avatar johnynek commented on July 17, 2024

this may have been due to the bug we tried to fix with #51

from bazel-deps.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.