Skip to content

Instantly share code, notes, and snippets.

@jebeaudet
Last active April 30, 2024 17:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jebeaudet/3990732c3e2ae32f7df4e39af698d982 to your computer and use it in GitHub Desktop.
Save jebeaudet/3990732c3e2ae32f7df4e39af698d982 to your computer and use it in GitHub Desktop.
Manual patching of ECJ jar for IntelliJ issue

This is what I've done to circumvent this issue. For my project to work, I need the -parameters option and I also like the -preserveAllLocals for debugging.

As IntelliJ accepts a custom ECJ jar, I figured I'd recompile ECJ with the options hardcoded to get around that bug. Unfortunately, the documentation is quite sparse and doesn't show an easy way to build ecj.jar.

I've decided to modify the jar instead! There is a neat tool called Recaf that does just that, decompiles a jar and allow you to easily modify it and repackage it. Neat!

  1. Head to mvn repo to download the latest jar
  2. Download recaf fat jar and execute it with java -jar recaf-2.21.13-J8-jar-with-dependencies.jar
  3. Open the ecj jar in Recaf by using File -> Load
  4. Open the class Main.java in org.eclipse.jdt.internal.compiler.batch
  5. For some reason, Recaf couldn't properly decompiled the class so I went to the Eclipse JDT core repo to fetch the real source code (you could also fetch it from the source jar to use the exact version, it would be more robust than what I did). MAKE SURE the main class is the one bundled in the jar!
  6. At the end of the configure method of the class, add this :
this.options.put(CompilerOptions.OPTION_MethodParametersAttribute,CompilerOptions.GENERATE);
this.options.put(CompilerOptions.OPTION_PreserveUnusedLocal,CompilerOptions.PRESERVE);
  1. Save the file
  2. File -> Export program -> choose a jar name (ecj-patched.jar)
  3. java -jar ecj-patched.jar will now complain about invalid signature of the class, easy to fix with zip -d ecj-patched.jar 'META-INF/.SF' 'META-INF/.RSA' 'META-INF/*SF'

Now, just use this patched jar in IntelliJ and this should work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment