paperweight
paperweight copied to clipboard
(core/patcher): Gradle incremental compilation broken
While trying to find out why hot reloading single classes takes "ages", I found out, that when Gradle is no longer forced to recompile everything (through the log4j2 annotation processor) and instead uses incremental compilation, it fails with lots of compiler errors: https://paste.gg/p/anonymous/6b0dcd7a59b04cf5a5eb3ad653530714
The reason for the compiler errors is that paperweight adds the remapped jar as a dependency:
https://github.com/PaperMC/paperweight/blob/3f6c7a5febd8be3fec45774341714011573fc7c0/paperweight-lib/src/main/kotlin/io/papermc/paperweight/util/project-util.kt#L82
This dependency ends up being the first entry in the javac classpath argument (I don't know much about gradle internals but after some playing around with the code and googling I believe that through gradle's dependency resolution file
dependencies always end up at the beginning in front of any non-file dependency).
In incremental compilation, gradle instructs javac to compile only those classes that have changed (and dependants). Any missing class will be loaded from the files defined in the classpath where the remapped jar is the first entry to be searched in.
javac will load any NMS related class from the remapped jar which then causes compiler errors as these classes are the wrong ones.
I wrote a discord message while investigating this morning (it contains a little more in-depth info on what I did): https://discord.com/channels/289587909051416579/555462289851940864/1119107748030844938
Screenshot of the message
Simple Reproduction
- Spin up a clean PaperMC project
- Remove the log4j annotation processor from Paper-Server
- Run
./gradlew compileJava
- This one should run as it has no cache yet and performs a full recompilation
- Change something in a class (in my case I added a println to the constructor of
EmptyLevelChunk
) - Run
./gradlew compileJava
- This run should fail now. If you want, you can add a
--info
to see whether (and why) gradle compiles - Adding
--debug
and searching forcompiler arguments
should lead you to the javac command args
- This run should fail now. If you want, you can add a
The log4j annotation processor is currently the only reason why this bug has not been noticed. If Apache marks it as incremental or maybe Gradle further improves the incremental compilation, then this will probably break every non-CI build. A quick workaround would be to disable the incremental compilation feature.
While browsing around in the source of paperweight I've noticed that @Machine-Maker recently added a task that generates a filtered remapped jar. I've tried to use that jar instead of the normal remapped jar. It resolved most of the compiler errors. But I'm getting new errors towards LogUtils.getClassLogger()
missing. I'll maybe look into that later today.