Vaadin/GWT compilation fails with InvalidClassException - JDeclaredType;

I’m migrating my application from Vaadin 6 to 7.

environment:
Maven 3.0.4
OS: tried Windows 7 and Linux
Oracle JDK 64bit 1.7.0_11
Vaadin 7.0.0

[INFO]
    [ERROR]
 Unexpected internal compiler error
[INFO]
 java.lang.RuntimeException: Unexpected IOException on in-memory stream
[INFO]
  at com.google.gwt.dev.javac.CompilationUnit.getTypes(CompilationUnit.java:360)
[INFO]
  at com.google.gwt.dev.jjs.impl.UnifyAst.assimilateUnit(UnifyAst.java:672)
[INFO]
  at com.google.gwt.dev.jjs.impl.UnifyAst.searchForTypeBySource(UnifyAst.java:985)
[INFO]
  at com.google.gwt.dev.jjs.impl.UnifyAst.addRootTypes(UnifyAst.java:530)
[INFO]
  at com.google.gwt.dev.jjs.JavaToJavaScriptCompiler.precompile(JavaToJavaScriptCompiler.java:621)
[INFO]
  at com.google.gwt.dev.jjs.JavaScriptCompiler.precompile(JavaScriptCompiler.java:33)
[INFO]
  at com.google.gwt.dev.Precompile.precompile(Precompile.java:278)
[INFO]
  at com.google.gwt.dev.Precompile.precompile(Precompile.java:229)
[INFO]
  at com.google.gwt.dev.Precompile.precompile(Precompile.java:141)
[INFO]
  at com.google.gwt.dev.Compiler.run(Compiler.java:232)
[INFO]
  at com.google.gwt.dev.Compiler.run(Compiler.java:198)
[INFO]
  at com.google.gwt.dev.Compiler$1.run(Compiler.java:170)
[INFO]
  at com.google.gwt.dev.CompileTaskRunner.doRun(CompileTaskRunner.java:88)
[INFO]
  at com.google.gwt.dev.CompileTaskRunner.runWithAppropriateLogger(CompileTaskRunner.java:82)
[INFO]
  at com.google.gwt.dev.Compiler.main(Compiler.java:177)
[INFO]
 Caused by: java.io.InvalidClassException: com.google.gwt.dev.jjs.ast.JDeclaredType; local class incompatible: stream classdesc serialVersionUID
 = -1052417216019896795, local class serialVersionUID = -8155793964565947646
[INFO]
  at java.io.ObjectStreamClass.initNonProxy(ObjectStreamClass.java:604)
[INFO]
  at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1601)
[INFO]
  at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1514)
[INFO]
  at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1601)
[INFO]
  at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1514)
[INFO]
  at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1750)
[INFO]
  at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1347)
[INFO]
  at java.io.ObjectInputStream.readObject(ObjectInputStream.java:369)
[INFO]
  at java.util.ArrayList.readObject(ArrayList.java:733)
[INFO]
  at sun.reflect.GeneratedMethodAccessor17.invoke(Unknown Source)
[INFO]
  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[INFO]
  at java.lang.reflect.Method.invoke(Method.java:601)
[INFO]
  at java.io.ObjectStreamClass.invokeReadObject(ObjectStreamClass.java:1004)
[INFO]
  at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1866)
[INFO]
  at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1771)
[INFO]
  at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1347)
[INFO]
  at java.io.ObjectInputStream.readObject(ObjectInputStream.java:369)
[INFO]
  at com.google.gwt.dev.jjs.ast.JProgram.deserializeTypes(JProgram.java:203)
[INFO]
  at com.google.gwt.dev.javac.CompilationUnit.getTypes(CompilationUnit.java:358)
[INFO]
  ... 14 more

here’s the pom.xml fragment:

 <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.1.1</version>
                <configuration>
                    <warSourceDirectory>src/main/webapp</warSourceDirectory>
                </configuration>
            </plugin>
            <!-- Compiles your custom GWT components with the GWT compiler -->
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>gwt-maven-plugin</artifactId>
                <version>2.5.0</version>
                <configuration>
                    <!-- if you don't specify any modules, the plugin will find them -->
                    <!--modules>
                        ..
                    </modules-->
                    <webappDirectory>${project.build.directory}/${project.build.finalName}/VAADIN/widgetsets
                    </webappDirectory>
                    <extraJvmArgs>-Xmx512M -Xss1024k</extraJvmArgs>
                    <runTarget>clean</runTarget>
                    <hostedWebapp>${project.build.directory}/${project.build.finalName}</hostedWebapp>
                    <noServer>true</noServer>
                    <port>9944</port>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>resources</goal>
                            <goal>compile</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <!-- Updates Vaadin 6.2+ widgetset definitions based on project dependencies -->
            <plugin>
                <groupId>com.vaadin</groupId>
                <artifactId>vaadin-maven-plugin</artifactId>
                <version>${vaadin.version}</version>
                <executions>
                    <execution>
                        <configuration>
                            <!-- if you don't specify any modules, the plugin will find them -->
                            <!--
                            <modules>
                                <module>${package}.gwt.MyWidgetSet</module>
                            </modules>
                            -->
                        </configuration>
                        <goals>
                            <goal>update-widgetset</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

I added my comment to this GWT bug report:
http://code.google.com/p/google-web-toolkit/issues/detail?can=2&start=0&num=100&q=&colspec=ID%20Type%20Status%20Owner%20Milestone%20Summary%20Stars&groupby=&sort=&id=7530

but I’m wondering if there’s any workaround…

This could be due to some old unit cache lingering in your build. You could try manually removing any unit-Cache directories from your build and see if it helps.

I tried deleting gwt-unitCache folder, then restarting the Maven build:

mvn clean package -DskipTests

same problem.

note that “clean” stage deletes “target” folder, which contains gwt-unitCache subfolder, so deleting this folder manually before the build would not have any benefit.

I wonder if there is a dependency collision here since you are using both the gwt-maven-plugin and the vaadin-maven-plugin. The gwt plugin depends on GWT 2.5 while the vaadin plugin also includes GWT making the same classes available twice on the classpath. You could try removing the gwt plugin and see if it helps, also the classpath should not include gwt-dev or gwt-user since they are included in vaadin-client already.

but how will it know that it needs to compile the widgetset if I remove “gwt-maven-plugin” from the build?
I commented it out for now and the build passes, but it does not generate the JS code.

then I brought “gwt-maven-plugin” back and commented “vaadin-maven-plugin” out. now the build fails again. so it’s most likely a bug in Maven GWT plugin.

I see the build succeeds when I switch to the old Maven GWT 2.4.0:

                <groupId>org.codehaus.mojo</groupId>
                <artifactId>gwt-maven-plugin</artifactId>
                <version>2.4.0</version>

For Vaadin 7, the Vaadin Maven plug-in includes the functionality of the GWT plug-in (with the prefix “vaadin:” instead of “gwt:”) so you can use e.g. “mvn vaadin:clean vaadin:compile” - no need for the old GWT plug-in.