Search code examples
mavengwtguicegwt-ginowl-api

GWT (Maven) project: Dependency conflict


I have a GWT project with the following dependencies

    <dependency>
        <groupId>com.google.gwt.inject</groupId>
        <artifactId>gin</artifactId>
        <version>2.1.2</version>
    </dependency>

    <dependency>
        <groupId>net.sourceforge.owlapi</groupId>
        <artifactId>owlapi-distribution</artifactId>
        <version>4.0.2</version>
    </dependency>
  • gin 2.1.2 depends on guice 3.0 while owlapi 4.0.2 depends on guice 4.0-beta.

  • gin is used on the client side while owlapi is used on the server side.

  • Compilation fails when I force guice 4.0-beta to be used. Caused by java.lang.ClassNotFoundException: com.google.inject.internal.util.$Maps

  • Compilation succeeds when I force guice 3.0 to be used, but fails at run-time caused by java.lang.ClassNotFoundException: com.google.inject.internal.guava.collect.$ImmutableList

  • Downgrading the version of owlapi is not an option.

What options do I have to make this work? Can I use dependency scopes somehow while still retaining a functioning GWT DevMode?


Solution

  • Split your project in distinct modules. Given Maven's limited (by design) dependency scoping options, this is really the way to go.

    Use one module for client-side code, using only client dependencies (GIN with Guice 3), and one module for server-side code, using only server dependencies (OWLAPI with Guice 4); and have your client module compile your code to JS and package them as a WAR, that you can use as an "overlay" in the server module (or possibly use a third module that depends on both client and server if you prefer). If you have shared code, use a third/fourth shared module that both client and server modules depend on; the shared module would call maven-source-plugin's jar-no-fork goal so the client module could depend on the shared sources.

    You can find archetypes following this approach at https://github.com/tbroyer/gwt-maven-archetypes. They use my Maven Plugin for GWT, but earlier versions (you'd have to clone and mvn install the project then from the appropriate commit) relied on Mojo's Maven Plugin for GWT (my plugin is designed with multi-module projects in mind, and removed a lot of hacks that were needed previously when using Mojo's plugin).