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!
- Head to mvn repo to download the latest jar
- Download recaf fat jar and execute it with
java -jar recaf-2.21.13-J8-jar-with-dependencies.jar
- Open the ecj jar in Recaf by using File -> Load
- Open the class
Main.java
inorg.eclipse.jdt.internal.compiler.batch
- 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!
- 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);
- Save the file
- File -> Export program -> choose a jar name (
ecj-patched.jar
) java -jar ecj-patched.jar
will now complain about invalid signature of the class, easy to fix withzip -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!