Tuesday, February 24, 2015

GWT & Dagger 2

Hi all,

I've been trying Dagger 2 with GWT and have been fighting to get things working. Could someone help?

My pom:

<dependency>
 
<groupId>com.google.dagger</groupId>
 
<artifactId>dagger</artifactId>
 
<version>2.0-SNAPSHOT</version>
</dependency>
<dependency>
 
<groupId>com.google.dagger</groupId>
 
<artifactId>dagger-compiler</artifactId>
 
<version>2.0-SNAPSHOT</version>
 
<optional>true</optional>
</dependency>


[...]


<plugin>
 
<groupId>org.codehaus.mojo</groupId>
 
<artifactId>gwt-maven-plugin</artifactId>
 
<version>${gwtVersion}</version>
 
<executions>
 
<execution>
 
<goals>
 
<goal>compile</goal>
 
<goal>test</goal>
 
</goals>
 
</execution>
 
</executions>
 
<configuration>
 
<module>my.Module</module>
 
<extraJvmArgs>-Xmx2048M -XX:MaxPermSize=128M</extraJvmArgs>
 
<runTarget>index.html</runTarget>
 
<warSourceDirectory>${project.build.directory}/${tmpTargetDirectory}</warSourceDirectory>
 
<buildOutputDirectory>${project.build.directory}/${tmpTargetDirectory}/WEB-INF/classes/</buildOutputDirectory>
 
<hostedWebapp>${project.build.directory}/${tmpTargetDirectory}</hostedWebapp>
 
<webappDirectory>${project.build.directory}/${tmpTargetDirectory}</webappDirectory>
 
<webXml>${project.build.directory}/${tmpTargetDirectory}/WEB-INF</webXml>
 
<generateDirectory>src/main/java</generateDirectory>
 
<bindAddress>0.0.0.0</bindAddress>
 
<jsInteropMode>JS</jsInteropMode>
 
<closureCompiler>true</closureCompiler>
 
</configuration>
</plugin>


My issues are:

#1 generated sources aren't available for gwt compilation
running:

mvn compile

no errors are found in the compilation phase, dagger 2 generated sources land in target/generated-sources/annotations/

However running:

mvn compile gwt:compile

GWT compilation outputs the following error:

[ERROR] Errors in 'file:/path/to/project/src/main/java/path/to/project/client/ProjectEntryPoint.java'
[INFO] [ERROR] Line 79: No source code is available for type path.to.project.client.Dagger_ProjectComponent; did you forget to inherit a required module?
[INFO] [ERROR] Hint: Check the inheritance chain from your module; it may not be inheriting a required module or a module may not be adding its source path entries properly



the problem seems related with the fact that GWT compilation isn't including the generated sources, as target/generated-sources/annotations/ isn't included in the classpath of the GWT compiler. The project class paths that are included in GWT compile command are:
/path/to/project/target/tmp/WEB-INF/classes
/path/to/project/target/src/main/java


#2 Eclipse "doesn't follow" Dagger 2 generate sources (not related with GWT per-si)
I configured Eclipse (Luna edition) with m2e-apt plugin (http://marketplace.eclipse.org/content/m2e-apt). My project works as a maven project in Eclipse.

However when I change something in dagger (Component, Module, etc.) the generated sources aren't immediately generated, I need to do "Maven > Update Project".

#3 Eclipse imports errors on Dagger 2 generated files open (not related with GWT per-si)
When I open a file that was generated by dagger 2 (in target/generated/sources/annotations) eclipse doesn't know how to import other sources from target/generated/sources/annotations which lead to several compile time errors in those generated files. Additionally, from that point on Eclipse confuses himself and makes the project source files (in src/main/java) that are referring to generated dagger files (e.g. Dagger_ProjectComponent) to also be in error (eclipse doesn't know anymore to import those symbols).

To overcome this I have to do "Maven > Update Project". Note, however, that every time I open a dagger2 generated file, this happens again.

--
Has someone succeeded getting dagger 2 and GWT (and Eclipse) working together smoothly?

Also, any help to overcome the reported issues would be great (specially issue #1).

Thank you,
Vasco

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+unsubscribe@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at http://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment