gwtgwt-jsinterop

Controlling which classes GWT includes with -generateJsInteropExports


Can I control which classes are included when I use -generateJsInteropExports?

I'm finding that when I use the flag, the JS output includes a bunch of classes that I'm not using in the project, but whose source appears in some of the packages I'm using. I don't want these classes to be included in the output. Normally, GWT does a good job of only bringing in classes that I'm actually using.

How can I tell the compiler "in this compilation I'd like you to generate JsInterop for these classes, but not these"?

I found these GWT compiler options:

-includeJsInteropExports/excludeJsInteropExports

Include/exclude members and classes while generating JsInterop exports. Flag could be set multiple times to expand the pattern. (The flag has only effect if exporting is enabled via -generateJsInteropExports)

But I couldn't seem to get them to work. I tried using:

-generateJsInteropExports
-includeJsInteropExports com.example.MyClass

The class wasn't included.


Solution

  • The filtering is at the level of class member (i.e. fields and methods) rather than type name. To match all members of a class the syntax is:

    -generateJsInteropExports
    -includeJsInteropExports com.example.MyClass.*
    

    Note: It's a regular expression, so the dots represent "any character" rather than periods. You'd have to escape them if there were ambiguity.