Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cache java compilation

Is there any posibility to cache java compilation like ccache does for C or C++ compilation?

I have a lot code to compile, and I compile the same code many times, so it took a lot of time. So I thought to cached it to speed up.


But the main problem is that, the whole source code has many files in many directories, and there are so many java files. Compilation is done by the ant scripts which are invoked by the make script. It has to be compiled by the Sun's JDK. And what is more... between compilations I have to clean all created *class files.

So I cannot use any of IDE's features.

like image 223
kokosing Avatar asked Dec 14 '22 01:12

kokosing


2 Answers

Eclipse does incremental compile of classes (I guess others do this as well). Only the portion of your class that changes will be compiled. Everything else will not be changed. It works reasonably well in real world projects.

Build tools like Maven and Ant can be configured to compile only changed java files. These do not track dependencies in some scenarios they miss needed compiles. (For example change the signature in a super class.)

like image 113
Thomas Jung Avatar answered Dec 28 '22 12:12

Thomas Jung


The best way would be to factor the shared classes into utility jars that you would simply include in your compile classpath, unless there is really a specific (and good) reason that prevents you from doing so (code duplication is evil and will lead you to doom :)).

like image 21
Romain Avatar answered Dec 28 '22 14:12

Romain