bazel and dagger: problem finding generated sources

575 views
Skip to first unread message

Ryan McLoughlin

unread,
Jun 17, 2017, 11:35:14 PM6/17/17
to bazel-discuss

I’ve been able to use other code generating plugins (Google auto value and protocol buffers) with bazel but I’m having trouble with dagger.  Bazel seems to be unable to find generated sources/classes that are in a different java package than the one where they are used.

Please see this example repo:  https://github.com/rmcloughlin/blaze-dagger-issue

bazel is able to successfully use the dagger plugin to generate and then compile a source file for the “module” package:

$ bazel build java/module

(succeeds)

$ jar -tf bazel-bin/java/module/libmodule.jar

META-INF/

META-INF/MANIFEST.MF

module/

module/MyModule.class

module/MyModule_ProvideDateFactory.class  <- from generated source

but another package ("component") is unable to find that generated class, despite depending on //java/module:

$ bazel build java/component

bazel-out/local-fastbuild/bin/java/component/_javac/component/libcomponent_sourcegenfiles/component/DaggerMyComponent.java:7: error: cannot find symbol

import module.MyModule_ProvideDateFactory;

            ^

 symbol:   class MyModule_ProvideDateFactory

 location: package module

Target //java/component:component failed to build

 

 I assumed that //java/component would have access to everything inside libmodule.jar but apparently that’s not how things work.  Can anyone explain how to fix this?

Ryan McLoughlin

unread,
Jun 18, 2017, 9:51:27 AM6/18/17
to bazel-discuss
I figured it out.  The problem was that in my java_plugin declaration in my BUILD file I needed to add "generates_api = 1"

Ryan

Steren Giannini

unread,
Jun 19, 2017, 4:53:32 AM6/19/17
to Ryan McLoughlin, bazel-discuss
Hi Ryan,
Thanks for the update, glad you could solve your problem. For this kind of support question, we recommend posting StackOverflow questions (and answers). The reason is that other developers will be able to find it more easily than on this mailing list.

Steren

--
You received this message because you are subscribed to the Google Groups "bazel-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bazel-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bazel-discuss/4c62e2cd-6370-406e-b285-e4c315ce8783%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages