I have to clean up an old project and general knowledge here is that the project contains lots of unused code that we could remove. That would save some headaches and make maintenance easier.
I found the Eclipse Core Tools plugin which looks like a great tool, but in our case we have a Maven2 project that is split in 3 modules.
I can’t seem to be able to run the “find unreferenced members” on the parent project, and when I run it on one of the modules it ignores completely the fact that other modules might be using some of the public members…
Anyone has overcome that issue? Or found another way to go about this?
Thanks.
Yes, that’s the problem, and that’s why there is no real deterministic way to do find unused code as reminded by @cletus in this previous answer.
Having that said, tools like PMD (and its unusedcode rule), Findbugs may help anyway. IDEs like IntelliJ (Java code inspections are fully available in the Community Edition) and Eclipse also have good support for this.
For IntelliJ, have a look at Global unused declaration inspection:
For Eclipse, there is the UCDetector plugin:
But I confess that I’m not sure if any of these solution will really work across modules. In that case, my suggestion would be to put all the code in one “janitor” project (yeah, this is ugly but well…) and to run the tools on it (and to clean modules based on the obtained results).