GWT + Maven + GPE gotchas

Lately, the support of Maven for the Google Plugin for Eclipse (GPE) has been enhanced. Since GPE 2.1, you can File | Import… | Existing maven project, point it to your POM, and everything should just work. You can start the development mode without running any additional goals like ‘mvn eclipse:eclipse’ anymore. Or at least this is what I ‘d like to see happening while trying out the new GPE, but…

GEP fails to locate module descriptor in “src/main/resources”
Maven2 philosophy dictates that all non-java resources that should be available on the classpath should reside on “src/main/resources”. While placing your gwt.xml file under “src/main/resources” will work with ‘mvn gwt:run’, GPE will fail to discover it even if the <module/> configuration property of the gwt-maven-plugin has been specified. No matter what, running your app in Eclipse (Run | Run As | Web Applicaiton) will result in the following error:

Missing required argument 'module[s]'
Google Web Toolkit 2.3.0
module[s]        Specifies the name(s) of the module(s) to host

This one turned out to be a known GPE issue (Issue 3759) and the recommended workaround is to place your GWT module descriptor in “src/main/java”.

Contents of “src/main/webapp” are not getting copied to the hostedWebapp *Solved*
While running the development mode server the resources of “src/main/webapp” are expected to be found under the hostedWebapp directory (i.e. target/${}) and using the copyWebapp configuration property should have copied them. Unfortunately, this is still not working for me and I ‘ve experienced errors like FileNotFoundExceptions and 404 errors despite using the AppEngineLauncher or the internal Jetty server.
To get around this, I have to run ‘mvn war:exploded‘ before starting the development mode. Read also this FAQ entry.

Update: As commented by David Chandler, in order for the GPE to copy the “src/main/webapp” to the hostedWebapp directory, you need to have the m2extras’ “Maven Integration for WTP” plugin installed as well as m2eclipse. Here is the m2extras update site:

No App Engine SDKs found on the build path
This is a minor but annoying one. GPE will search your POM’s dependencies for a GAE SDK and if it doesn’t find one (let’s say because you don’t use GAE), Eclipse will report the following problem:

Google App Engine Problem (1 item)
 > The project 'xxx' does not have any App Engine SDKs on its build path

To get rid of it you can either go to Project | Properties | Google | App Engine and deselect ‘Use Google App Engine’ or consider adding a dependency for GAE SDK in your POM

This entry was posted in GWT and tagged , , , , . Bookmark the permalink.

8 Responses to GWT + Maven + GPE gotchas

  1. To me (because I haven’t found anything really explicit in the docs), src/main/resources contains the files that should be included (copied) in the generated artifact (so they’ll be on the classpath of any other module depending on this module). In the case of GWT, the gwt.xml files really are “sources”, more than “resources” (even though they’re abviously not Java). Even when building a GWT library, it’s not a problem having them in a “sources” (as opposed to “resources”) folder, because you’ll have to package the *.java as well, which are also in a “sources” folder; it actually even makes it easier to build “shared” libraries: the generated “jar” contains only *.class files, and the “sources jar” contains the *.java and any other file needed by GWT (including of course *.gwt.xml).
    But again, I believe there should be a specific Maven “packaging” for GWT projects, so that having a single dependency on an artifact with a type=gwt would suffice (as opposed to nowadays’ two dependencies, on both type=jar and type=sources artifacts).

    • jgonian says:

      I can see your point treating gwt.xml files as “sources” and I don’t disagree with you in terms of the GWT world. However, AFAIC in the maven world – even if the docs aren’t strict about it – there is the commonly adopted convention that anything which doesn’t end with .java shouldn’t be placed on “src/main/java“. Take for example the gwt-maven-plugin archetype which places the gwt.xml file on “src/main/resources” folder…
      Regarding the gwt specific packaging type, I really liked your idea! It could save up a lot of time spent on configurations and puzzling. Do you know if it is discussed anywhere?

    • Maybe GWT sources shouldn’t be put in src/main/java, but they shouldn’t live in src/main/resources either; and IIRC the issue with GPE and src/main/resources is that GPE uses the classpath, and M2Eclipse puts an “exclude=*” rule on src/main/resources. I haven’t tried but maybe using a src/main/gwt, as a “sources” folder, would work.

      Re. my proposal, no, I don’t know if it’s discussed; I don’t even know where that would/should be discussed. At first, I’d say the gwt-maven-plugin list, and it’s definitely not being discussed there. Such a new packaging would need additional specific support from GPE, but I believe David Chandler would relay the need to the GPE team (and/or we could Cc: Chris Ramsdale).
      I still consider myself “new” to Maven (only using it for less than a year), so I don’t think I’m the one who should pursue this idea; unless some “Maven guru” supports it and asks me to go ahead. And even then, as Nicolas De Loof, I’m not sure I could spend much time coding the extension (and given that no-one continued the discussion on the gwt-maven-plugin list, it seems like no-one would help either)

  2. Thanks for the write-up. I have in fact relayed this to the GPE team. I’m a bit puzzled as to why you can’t import and run the gwtgae2011 project successfully, however. You certainly shouldn’t be getting the App Engine SDK errors because the POM includes it.

    • jgonian says:

      You ‘re welcome!
      No, I ‘m not getting the App Engine SDK error for gwtgae2011 project but for other non-GAE projects.

      As to why I can’t run the gwtgae2011 project, is because the contents of src/main/webapp aren’t getting copied to the target/gwtgae2011-1.2-SNAPSHOT/ directory. I can’t come up with a better explanation why this is happening – than to blame the copyWebapp property – but I did reproduced the problem consistently with every project that I’ve tried (inlcuding gwtgae2011, listwidget, gwtp samples).

  3. Can you confirm that you have Sonatype m2extras plugin installed as well as m2eclipse? GPE depends on the WTP Maven integration provided by m2extras in order to copy src/main/resources to target/…

    • jgonian says:

      You ‘re right! the plugin was missing and by installing it the problem solved. Thanks a bunch David! I will update my post to include the missing part.

      I miss intelliJ’s intuitive maven support, already…

  4. techfixerhdave says:

    Would like to also thank you for the GWT-Maven-GPE project on github. It was a big help to me. A couple of comments on that though:

    1) In your pom.xml file you supply various dependencies to GPE such as gwt-user, gwt-dev, gwt-servlet. I believe these are not necessary.

    2) Since GWT 2.1, it seem that the plug version MUST cooincide withe GWT (SDK) version you are using, so I would recommend not using two properties to control those, but have the plugin use ${gwt.version}

    3) At least with GWT 2.4, I could not reproduce your issue where the GAE is checked by default. When I imported your project without modifications, GAE was not enabled.

    Thanks again.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s