Dagger: Instructions for Bazel do not work

Created on 16 Feb 2019  路  8Comments  路  Source: google/dagger

Following the instructions in the main readme for Bazel do not work.

I am getting this:

ERROR: Analysis of target '//:Main' failed; build aborted: no such package '@com_google_dagger//': BUILD file not found on package path

WORKSPACE:

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

http_archive(
    name = "com_google_dagger",
    urls = ["https://github.com/google/dagger/archive/dagger-2.21.zip"],
)

maven_jar(
    name = "org_json",
    artifact = "org.json:json:20141113",
)

maven_jar(
    name = "com_google_guava_guava",
    artifact = "com.google.guava:guava:21.0",
    sha1 = "3a3d111be1be1b745edfa7d91678a12d7ed38709",
)

maven_jar(
    name = "com_google_guava_guava_testlib",
    artifact = "com.google.guava:guava-testlib:21.0-rc1",
    sha1 = "13f0f0dce4e710bb0bb791bd07f6e9858670a865",
)

BUILD:

java_binary(
    name = "Main",
    srcs = 
        glob(["src/**/*.java"]),
    deps = [
        "@org_json//jar",
        "@com_google_guava_guava//jar",
        "@com_google_dagger//:dagger_with_compiler",
    ]
)

Most helpful comment

I think this issue should be reopened. The instructions on the readme for using Dagger with Bazel are still as the original poster described, and they still produce the same results when you try to follow them.

The instructions that were added by @ronshapiro at https://github.com/google/dagger/issues/1422#issuecomment-483740264 as the reason for closing this issue appear to be for setting up your development environment for hacking on dagger itself, not for using it in another project.

The instructions posted by @mancini0 at https://github.com/google/dagger/issues/1422#issuecomment-513581156 do appear to work, so if there is no way to update the instructions in the current readme so that they do work, maybe they should be changed to follow the alternate approach his example lays out.

All 8 comments

Note, the first issue seems to be the subdirectory within the ZIP file. If the prefix is stripped, we get further. But then it complains because it doesn't seem to use the WORKSPACE dependencies from the dagger archive and throws this error:

ERROR: Analysis of target '//:Main' failed; build aborted: error loading package '@com_google_dagger//': Unable to load package for '@google_bazel_common//tools/jarjar:jarjar.bzl': The repository could not be resolved

Here is the modification to the WORKSPACE file to strip the prefix:

http_archive(
    name = "com_google_dagger",
    urls = ["https://github.com/google/dagger/archive/dagger-2.21.zip"],
    strip_prefix = "dagger-dagger-2.21",
)

You need to also load in github.com/google/bazel-common, which Dagger depends on. That's what that error is.

I did try this as well but then ran into other issues. I never got it to build.

It would be great to get verified build instructions updated in the README that are definitely working.

We just added some to 19f768d1d65750398caabb75bfe31874ca01b999. Feel free to reopen specific issues if that's not working, or pull requests if you notice anything that is incorrect.

I pushed an example working bazel configuration at this demo repo. (look at the capitalization service in branch dagger)

https://github.com/mancini0/bazel-grpc-playground/tree/dagger

bazel build //capitalization:app

Note that the //capitalization:capitalization-service-test fails when using dagger, (but works fine on the master branch, which does not use dagger.) I just noticed there is a dagger-grpc library so I suspect something in dagger does not play nicely with grpc, but I have yet to investigate.

I also could not use (suggested above) github.com/google/bazel-common, (I hit some protobuf error),
so I configured dagger using the native java_plugin bazel rule. I think the readme should probably suggest my approach.

I think this ticket should be reopened, as the bazel instructions in the readme are currently incorrect.

I think this issue should be reopened. The instructions on the readme for using Dagger with Bazel are still as the original poster described, and they still produce the same results when you try to follow them.

The instructions that were added by @ronshapiro at https://github.com/google/dagger/issues/1422#issuecomment-483740264 as the reason for closing this issue appear to be for setting up your development environment for hacking on dagger itself, not for using it in another project.

The instructions posted by @mancini0 at https://github.com/google/dagger/issues/1422#issuecomment-513581156 do appear to work, so if there is no way to update the instructions in the current readme so that they do work, maybe they should be changed to follow the alternate approach his example lays out.

Would a PR be accepted that installed these dependencies as part of an exported dagger_repositories() macro, like is done in other bazel rules meant to be consumed externally?

Also, has there been any discussion about moving to rules_jvm_external instead of maven_jar?

@austince, coincidentally, we're working on this now. I'll update the docs once this is in.

We'll be using rules_jvm_external/maven_install for the macro, but that should just be an implementation detail for users calling the macro.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

matpag picture matpag  路  3Comments

6bangs picture 6bangs  路  3Comments

vorburger picture vorburger  路  4Comments

feinstein picture feinstein  路  3Comments

SteinerOk picture SteinerOk  路  3Comments