Removing Unused Dependencies in IDEA Projects

In this post I write about Jonnyzzz Dependencies plugin that helps one to remove unused dependencies between modules and libraries

Problem Statement

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=commited 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.

Plugin Sources

You may download a build of the plugin repository. Plugin is provided under Apache 2.0 license. Sources are on GitHub

comments powered by Disqus