Darwly
Darwly

Reputation: 344

How to workaround: No source is available for type did you forget to inherit a required module?

In shared package i have a class that only uses a class from server package, only when it is on server, it is indepdendant of the GWT, and i have made it transient

if (!GWT.isClient())
    ServerLogger loggerServer;

but it does not compile because it is in shared.. Can i worourund in here?, I just want for the GoogleCompile to work, it should not have the functionality of the server logger. Is there a workaround?

How to write my own module which is NULL overall, because i only want to stop the compiler of erroring.

Upvotes: 1

Views: 555

Answers (1)

Jason Hall
Jason Hall

Reputation: 20920

GWT is still trying to compile this code. You will want to use Deferred Binding and <super-source> to swap in the implementation you need at compile-time, so that GWT doesn't try to compile this server-specific code.

Either that, or have the ServerLogger implementation be an interface dependency on this shared class, and pass in the correct implementation in server/client:

// in your shared package

public class SharedClass {
  private final LoggingClass logging;
  public SharedClass(LoggingClass logging) {
    this.logging = logging;
  }

  public void log(String msg) {
    logging.log(msg);
  }
}

public interface LoggingClass {
  public void log(String msg);
}

// in your client package

public class ClientLogging implements LoggingClass {
  public void log(String msg) { GWT.log(msg); }
}

// in your server package

public class ServerLogging implements LoggingClass {
  public void log(String msg) { ServerLogger.log(msg); }
}

Upvotes: 2

Related Questions