javagwtgwt-compiler

Does GWT remove unused classes during compilation?


Suppose I have a project structure that looks roughly like this:

{module-package}.webapp  
    module.gwt.xml
{module-package}.webapp.client
    Client.java
    UsedByClient.java
    NotUsedByClient.java

And the module.gwt.xml file has:

<source path='client'/>
<entry-point class='{module-package}.webapp.client.Client'/>

When I compile this project using GWT, how much of the Java code will be compiled into Javascript?

The motivation is that unfortunately I'm working with a legacy codebase that has server-side code living alongside client-side code in the same package and it would be some work to separate them. The server-side code isn't used by the client, but I'm concerned that GWT might compile it to Javascript where someone might notice it and try to reverse engineer it.


Solution

  • All of the above and more happen:

    And this process repeats, with even more optimizations that I skipped, to further assist in removing code, both big and small. At the end, all classes, methods, fields, and local variables are renamed in a way to further reduce output size, including reordering methods in the output so that they are ordered by length, letting gzip more efficiently compress your content on the way to the client.

    So while some aspects of your code could be reverse engineered (just like any machine code could be reverse engineered), code which isn't referenced won't be available, and code which is may not even be readable.