tbroyer / gwt-maven-archetypes

Apache License 2.0
152 stars 39 forks source link

Synchronism between client and shared #30

Closed reinert closed 9 years ago

reinert commented 9 years ago

When working in client, I made a breaking change on a class in shared module. Then after trying to recompile in SDM, I got compiling issues (API incompatibility).

After trying compile and package lifecycles, I realized that only by installing shared module, I could synchronize shared compiled code to client. Then I had to restart SDM again.

Is there a better way to get shared module synchronized with client when working in SDM?

tbroyer commented 9 years ago

Did you use the dev profile (using either -Ddev or -Pdev) ? It adds the shared modules' sources to the client modules' resources so they're available to GWT.

There might however be a class of changes that require running javac again and relaunching DevMode / SDM.

reinert commented 9 years ago

Yeah, I was using dev profile.

The problem was related to the resources inclusion.

The only way I could get it to work was adding sources instead of resources in the compie phase.

The build-helper-maven-plugin was configured as following:

<phase>compile</phase>
<goals>
  <goal>add-resource</goal>
</goals>
<configuration>
  <resources>
    <!-- Only sources, resources are already in the classpath, by definition -->
    <resource>
      <directory>${basedir}/../gwtthiago-shared/src/main/java</directory>
    </resource>
  </resources>
</configuration>

I had to change to:

<phase>compile</phase>
<goals>
    <goal>add-source</goal>
</goals>
<configuration>
    <sources>
        <!-- Only sources, resources are already in the classpath, by definition -->
        <source>${basedir}/../gwtthiago-shared/src/main/java</source>
    </sources>
</configuration>

Actually, I don't quite understand why it was configured to include the shared sources as 'resources'. Was it supposed to work?

tbroyer commented 9 years ago

You don't want the shared classes to be compiled into the client's target/classes, this is why it was set as add-resource. Now we could maybe use add-source in the process-classes phase? But what we really want is have the sources in the classpath, so add-resource should work as advertized.

What kind of "breaking change" did you do in the shared class? Also, with your add-source setup, did the shared classes imported this way end up being compiled by the maven-compiler-plugin as part of the client build?

reinert commented 9 years ago

Ok! Now I clearly understand!

Actually my problem wasn't in the client POM, but in shared.

It happens that I'm using gwt-maven-plugin generateAsync goal, and the sources generated in another folder wasn't being compiled!

Although in the client I was referencing the shared generated folder...

<resource>
  <directory>${basedir}/../gwtthiago-shared/target/generated-sources/gwt</directory>
</resource>

... I wasn't including this folder in the shared compilation. So client's compilation couldn't find any compiled classes there, only sources! I solved by adding the generated sources folder in shared compilation with build helper plugin.

Thanks for helping me out!

tbroyer commented 9 years ago

Note: generateAsync should add its output directory to the project's sources without the need for the build-helper-maven-plugin. It's possible however that the generated code wouldn't be packaged in the sources JAR.

tbroyer commented 9 years ago

Actually you were right: gwt-maven-plugin purposefully doesn't add resources to the classpath, so add-source has to be used. Currently working on the fix.

reinert commented 9 years ago

Why 'purposefully'?

tbroyer commented 9 years ago

See https://jira.codehaus.org/browse/MGWT-350 (and https://jira.codehaus.org/browse/MGWT-348)