How can I obfuscate Java source code for external GWT development?

别等时光非礼了梦想. 提交于 2019-12-07 22:45:01

问题


Most obfuscation focuses on bytecode. I have to supply the source code too as that is what a GWT compiler an external developer would use needs to run. Before releasing the source code I need to clean it up a bit:

  • Obfuscate method variable names
  • Obfuscate private method argument names
  • Remove all non-Javadoc comments except for the licence at the top of each file.
  • Remove all Javadoc comments on private methods or protected methods of final classes.
  • Remove certain Javadoc tags such as @author
  • Remove certain other comment tags such as TODO, FIXME, etc.
  • Remove all @see references to private classes
  • Remove all whitespace

Alternatively to the above all comments and all Javadoc could be removed (licence still needed at the top of each file) and I'd generate Javadoc separately.

I have not found a way that I could be sure would work nicely from within a gradle build script executed on multiple platforms. Some very old and no longer maintained solutions may have trouble with Java enhancements such as diamond operators and lambdas.

Are there any recommendations as to how I could do this?

Note that there are many questions like this unanswered here. One of them: GWT Java Obfuscation


回答1:


Nothing appears to be available for this TODAY:

  1. There are very few tools that work on Java source code obfuscation to begin with.
  2. Some of these are either not free or are not Java based.
  3. Source code (formatting) tools that remain are not customizable enough to remove all the comments but leave the GWT "JSNI" code in (GWT's way of embedding JavaScript code into Java within special /*-{ ... }-*/ style comments of "native" methods.

In the end, I wrote a simple bit of code myself that only takes out all the whitespace but leaves the JSNI code in and untouched. It does not obfuscate method variables or anything else but it will have to do for now.



来源:https://stackoverflow.com/questions/28948302/how-can-i-obfuscate-java-source-code-for-external-gwt-development

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!