In this post I write about Jonnyzzz Dependencies plugin that helps one to remove unused dependencies between modules and libraries
Let's say you have a project of 20+ modules. This project is quite
old, there are a number of dependencies between modules and libraries. There were many people who pushed
changes to it. So the question is how to figure out and remove unused libraries and module dependencies. Jonnyzzz Dependencies plugin is
designed to help you to solve the issue easily
In the IDEA you'll find an action under main menu: Tools | Remove Unused Module Dependencies. Here you may analyze dependencies for selected number of modules or for entire project.
Results of search are shown in the dialog. Next you may remove all dependencies in one click!
Plugin Implementation Details
First of all, it was tricky to use ReadAction/WriteAction in IDEA API. Long running ReadAction in plugin code could easily lead to deadlock. When IDEA instance loses focus it attempts to get WriteLock to persist project, so this would be a deadlock with UI thread. The right thing is to to take ReadLock only for show time slots (but many times)
Implementation of the plugin is straightforward. For selected modules I take files, there I take all references and resolve them. Resolved elements allows me to find actual set of dependencies. Next I compute difference between project defined dependencies and actual computed dependencies. Thanks to a huge number of IDEA API classes I implemented this search to run in all available processor cores
There are integration tests in the plugin sources that helps me to check major plugin use-cases. That was amazing to have integration tests framework!
It was nice experience to write a real working plugin for Intellij IDEA platform!
This plugin analyzed only COMPILE and TEST dependencies. PROVIDED and RUNTIME dependencies are not analyzed.