incremental compilation question

incremental

#1

Hi,
I have been slowly converting our projects over from ant to gradle and things have been pretty straight forward so far. When I got to one of our bigger projects (~6000 java files), I quickly realized incremental compile was not the default yet. After enabling with options.incremental = true, my build was still taking forever for basic changes. I’d open up a file, add a few newlines to some pojo and rebuild. Running with --info was showing 3000+ files required to recompile. Surely I thought there was a bug in one of the source generation tasks, re-writing files each time, but was not the case. I read several posts about how advanced the incremental detection is, ie changing an internal method of a public api or classes containing constants to build the minimum, so I feel like I’m missing something when I add a new line to a getter method, and rebuilds half my project.

Are the incremental compilation improvements only for dependent projects/3rd party dependencies, not intra project? It seems within a project, if I change a source file, it recompiles all other source files that import that class regardless, and continues to recurse till no more dependents found and that becomes the set to recompile. While I appreciate that is the “correct” way of doing it, the basic timestamp detection like ant/make is much faster for most of our uses cases, and we understand the caveats of a potentially broken build.

Am I understanding the incremental detection in gradle properly? and if so, is there a way to change the detection strategy? ie what you currently do vs basic timestamp?


(Stefan Oehme) #2

Inside a single project there is no api change detection because we don’t parse source code. This could be improved in the future but is not yet planned. We will not support the broken timestamp strategy as it would undermine trust in Gradle.

If all of the code is being recompiled then you probably hit a class with a public constant. Constants can be inlined so we assume that anyone could depend on them. Use static methods instead of constants where you can.

If a lot, but not all files are recompiled that can be a sign of highly coupled code. Using interfaces or creating project boundaries can help there, making the code more modular and compilation faster.


#3

Which is the conclusion we have reached internally, thanks for the confirmation. Breaking up the code into hopefully smaller sub-modules should take advantage of the incremental improvements.