3

I have a project with multiple gwt modules, one of which is a library module without an entry point from which the other modules inherit. All the modules are contained in a single project built using maven and the gwt-maven-plugin. Unfortunately, building the project fails because gwt:compile is looking for the inherited module on the classpath when it compiles the main modules that inherit it. How do I get the library module on the classpath for the compilation of the main modules?

mreynolds0404
  • 183
  • 1
  • 13

3 Answers3

6

You're going to need to do some creative "Maven-ing," as I just made up the term to describe it. (In reality it probably isn't creative at all, but I'm a bit of a Maven newbie myself, so it stumped me for a while too).

You're right in a sense, the GWT comipler is looking for the inherited module's source on the classpath when it tries to compile your "main" module. To achieve this, you will need to add a dependency, to the main module's pom, on the library module's sources (strictly for the compile phase).

Something like this:

...
<artifactId>main-module</artifactId>
...
<dependency>
  <groupId>library-group</groupId>
  <artifactId>library-artifact</artifactId>
  <type>jar</type>
  <version>0.1-SNAPSHOT</version>
  <classifier>sources</classifier>
  <scope>compile</scope>
</dependency>
...

Now, where you get those sources from can differ. If you're just trying to do this from an IDE, like Eclipse, this is probably enough because the m2eclipse plugin is smart enough to know where to get those sources (if the library-module is also in your workspace). If this is your actual build process, then you will need to modify the library-module's pom to produce the -sources artifact along with the standard "library-artifact." So you'll end up with both:

library-artifact-0.1-SNAPSHOT.jar

and

library-artifact-0.1-SNAPSHOT-sources.jar

Hopefully it's more clear how the gwt-maven-plugin proceeds from that point.

Almost forgot, the one other question I've answered here might be of some use as well: GWT Project Structure.

Community
  • 1
  • 1
Jason482
  • 197
  • 1
  • 10
  • Thanks for the response. Some additional clarification on our situation: We are indeed using Eclipse and currently have our application set up as a single Eclipse project. Within this project we have several gwt modules that make up different areas of our application. It made sense to have another, entry-point-less module to house shared resources for the other modules to inherit. We figured it would require us to set up a new project for our application to depend on, which I think is what you are describing. But, is there a way to locate the resource module within the primary project? – mreynolds0404 Jun 15 '11 at 19:24
  • 2
    Ah, I missed the "single project" part, initially. Indeed, I'm describing a separate project/artifact. However, you should be able to do it just like you have inheritance set up between your other GWT modules. GWT module A's gwt.xml, you'd have "", where Module B is your shared GWT module (with a gwt.xml file, but entry-point-less, if you want). Now, it _should_ be easy for the GWT compiler to find the source for B, since they are all in the same Eclipse project. Have you tried turning Maven debug stack traces on (-X)? – Jason482 Jun 16 '11 at 19:03
  • For me the missing piece in this answer was how to create this sources artifact. It is as simple as adding the maven-source-plugin to your project as described here https://maven.apache.org/plugins/maven-source-plugin/usage.html – FLUXparticle Jan 14 '21 at 15:51
2

Ok, I was able to solve this by explicitly listing my GWT modules in the project's pom file's gwt-maven-plugin configuration. By doing this, I was able to enforce the order of GWT compilation, ensuring that the shared module was compiled first and available to the other modules that inherit from it during their compilations.

Here is an example of the config:

<configuration>
  <modules>
    <module>com.foo.gwt.shared.Shared</module>
    <module>com.foo.feature.one.gwt.One</module>
    <module>com.foo.feature.two.gwt.Two</module>
  </modules>
</configuration>

Thanks to Jason482 for all the help.

mreynolds0404
  • 183
  • 1
  • 13
0

I would have preferred to comment on the answer above but I do not have enough rep to do it. So I am posting my findings here.

Jason482's answer worked for me. Adding:

<classifier>sources</classifier> <scope>compile</scope>

to each of my sub-modules dependencies, inside the reactor pom, solved my issue.

The solution that mreynolds went with, adding GWT module references to the main pom file's gwt-maven-plugin configuration, seems to be necessary ONLY if you have other entry points in your GWT submodules. I did not, so that step was not necessary for me.

Darkane
  • 63
  • 1
  • 9