Modular JavaFX app and Proguard Gradle plugin

Hi,
I am having problems with obfuscating modular JavaFX app with Gradle plugin for Proguard. All is obfuscating ok jar is being created but module-info.class is completely destroyed.
When I exclude module-info.java from obfuscation file stays untouched but then classes in the file looses connection with module (names doesn’t correspond any more).

Does anybody know how to obfuscate JavaFx modular app with proguard?

Any help would be really appreciated

Thanks
Andrzej

Hi @Andrzej ,

Module-info.class is a valid class file, but it is not used by any other class, so ProGuard removes it by default. This appears to be related to a reported bug in ProGuard.

Explicitly keeping it as an entry point should solve that:

-keep class module-info

adding the following directive may also be necessary:

-keepattributes Module*

If this does not work, it most likely a project-specific issue which will need to be further investigated. I would start by trying the above approach.

Please let me know if anything is not clear.

Kind Regards,

Jack

2 Likes

Hi Jack,
In my application mofule-info.class is needed to compile project into one jar and then package it using jpackage for deployment, so I really need it to be there obfuscated.

I did try solution you mentioned, but keeping module-info is not working as after obfuscation all the opens and exports paths stay un-obfuscated and looses all the references to the whole module.

My only solution to that for now (which is pretty ugly) is following Gradle script:

  1. Build project without proguard and save module-info.class somewhere outside build directory
  2. Create input.map for proguard which includes all exports and opens from module-info.java
  3. Open module-info.class (binary) and replace parts of compiled names of exports and opens to names from the input.map (names have to be exactly the length of the original as it is already compiled file)
  4. Build obfuscated jar with proguard and unpack classes to the build directory overwriting original ones
  5. Overwrite module-info.class with the one that was manipulated in step 3
  6. Build the project using obfuscated classes and module-info.class
  7. jLink and jPackage to distribution

It works well as long as you don’t change your module-info.java very often, but once I do any changes I have to go to manual labour of manipulating already compiled class file.

This is the only way I can get application obfuscated and packaged. If there is any other, please do tell. If only proguard could use in.map to obfuscate module-info.java, that would be great and saved me a lot of hassle and time with manipulating already compiled class file.

If you have any ideas to make this process better I would appreciate.

Best regards
Andrzej

1 Like

Hi Andrzej,

Thank you for sharing your current solution, albeit inconvenient as you mentioned.

What version of ProGuard are you using? ProGuard 6.2.0+ should work, we released a fix for this in issue 712. If not, would be great if you can share a sample via github so we can replicate the issue on our end.

Best regards
Jack

1 Like

Hi Jack,
I am using com.guardsquare:proguard-gradle:7.0.1 gradle plugin for proguard.
I created very simple Javafx example to visualise problem in here:
https://github.com/apazurkiewicz/JavaFXTest.git
If you try tu build gradle jar with this proguard.conf then in your jar file module-info.class will be untouched but with wrong open and export paths (not obfuscated).
On the other hand if I try too run proguard task without ouptions:
-keep class module-info
-keepattributes Module*
then module-info will be reduced to one line and obviously will be broken.
As mentioned before the only workaround I found is to compile classes without obfuscation with applied map (at least for the class paths that are in module-info) and then manually edit module-info.class replacing classpaths to those from input map and overwriting module-info.class in obfuscated compilation… really tedious process.

Regards
Andrzej

1 Like

Hi @Andrzej

Adding this line

-keeppackagenames "**"

to your configuration file should resolve the issue. Please confirm if this solution works for you.

Best Regards,

Jack

2 Likes