I'm trying to write a custom plugin that will generate some code (specifically, a Dagger module) off of some of the xml files in my android project. I've been able to get the code to generate, but when I try and use the generated module in a Dagger Component, the Dagger compiler fails:
I've put together a small demo project that demonstrates the failure. There are two modules: the plugin and the android app (FYI: I had to comment out the plugin-related code in the apps' build.gradle until I had installed the plugin locally).
When I rebuild the app, the generated module shows up right where I expect it, and the dagger component sees it in IJ. But it is apparently not available at the time when the android-apt plugin invokes the dagger compiler (or that location is not included in code the compiler is looking at).
I've made sure to have all the compile tasks depend on my "generate" task, and the failing task is compileDebugJavaWithJavac
which should therefore know about my generated code.
For trying to include the source, I have:
AndroidSourceSet mainSourceSet = p.android.sourceSets.getByName('main')
LOG.info("Adding directory ${outputDir} to android source set ${mainSourceSet}")
mainSourceSet.java.srcDir(outputDir)
Despite this, I get:
Compiling with JDK Java compiler API.
C:\projects\java\android\android_plugin_demo\plugindemoapplication\src\main\java\com\bdl\plugindemoapplication\DaggerComponent.java:12: error: cannot find symbol
@Component(modules = PluginDaggerModule.class)
^
symbol: class PluginDaggerModule
C:\projects\java\android\android_plugin_demo\plugindemoapplication\src\main\java\com\bdl\plugindemoapplication\DaggerComponent.java:13: error: dagger.internal.codegen.ComponentProcessor was unable to process this interface because not all of its dependencies could be resolved. Check for compilation errors or a circular dependency with generated code.
public interface DaggerComponent {
^
2 errors
So, what magic am I missing to allow for the dagger compiler to see my generated code?