views:

307

answers:

7

I'm about to inherit a rather large Java enterprise project that has a large amount of third party dependencies. There is at least seventy JARs included and some of them would seem to be unused e.g. spring.jar which I know isn't used.

It seems that over the years as various developers have touched upon the code base they have all tried out new project-of-the-month type libraries.

How does one go about getting rid of these? Within reason of course, as clearly some dependencies are helpful to not have to re-invent the wheel.

I'm obviously interested in java based projects but I'm welcome to answers across languages that people think will be helpful.

+4  A: 

Personally, I think you have to start by assessing the scale of the problem. It's going to be fairly painful, but I'd make a list of the dependencies and work out exactly which parts of the project use which ones.

Then I'd work out exactly what features of each you're actually making use of (in many cases, you'll end up having a massive third party library which you're using a tiny part of).

Once you have this information, you'll at least know what you're dealing with.

My next step would be to look at all of the dependencies that you only use to a small extent. Checking around might uncover things that you could use from other libraries that would eliminate the lesser used libraries.

I'd also have a look around to see if there's anything small that you could just re-write and include in your own code-base.

Finally, I'd have a look around at the vendors of your dependencies and their competitors to see if the latest versions contain more functionality that will allow you to eliminate a few others.

Then you're just left wondering whether it's better to be highly dependent on a few vendors, or less dependent on a lot of vendors!! ;o)

Chris Roberts
+1  A: 

If you have a good set of automated tests, and you're looking to remove libraries which are not used at all, you could just use trial and error. One at a time, remove a library, and run your tests to see if everything still works. If not, put it back. Of course, if you can't even build without a library, you probably need it.

Basically, however you go about it, my idea is to remove them one at a time and see what breaks. If nothing breaks, odds are good you can just toss the library. If the problem is very minor (e.g. you need one method of one class in a large library), you might be able to code around it.

If you're dealing with a standalone application, you could give the JVM the -verbose:class option to see which classes are being loaded. This should give you messages like:

[Opened C:\Program Files\Java\jre1.6.0_04\lib\rt.jar]
[Loaded java.util.regex.Pattern$Single from C:\Program Files\Java\jre1.6.0_04\lib\rt.jar]
Adam Crume
+1  A: 

I read about an approach using instrumentation here, never tried it, but sounds reasonable.

André
+1  A: 

We went through an exercise like this, on a delphi codebase. We dramatically simplified our external dependancies. Basically, we went about it like this:

  • Catalogued all external libraries and components
  • Catalogued (using a file search tool) where they were used, and what for.
  • Removed everything we didn't use or didn't need (some libraries were used in code that was no longer needed).
  • Made a ranking of which libraries we favored, basing this on whether the library was actively developed, how much functionality it offered that we used, how difficult it was to port the code that used it to another library that we already used and so on.
  • Finally, we iteratively removed dependancies on libraries low on the list by porting that functionality to another library.

This was, however, quite a lot of work.

Joeri Sebrechts
+2  A: 

structure101 http://www.headwaysoftware.com/products/structure101/index.php It's a great tool for showing dependencies. I've been using it for a couple of years.

Javamann
+1  A: 

If you take the approach of "remove things until it won't compile" you need to be very careful about transitive runtime dependencies. If there's a good quality test suite, it can help, but you'll certainly need to run a test coverage tool like Cobertura to make sure that enough of the code is getting tested to exercise your full dependency graph.

How much code are you talking about? The review-based approach suggested by Joeri frankly seems the best to me; it has the added advantage of making you at least superficially familiar with all parts of the system. If you're just inheriting a big project, this is something you should probably take the time to do anyway.

Kris Nuttycombe
A: 

if you have a full regression test suite for this project, all you have to do is run the regression suite while running with 1 less JAR each time in a loop. it is NOT fast BUT it is easy to do.

anjanb
Suffice to say that there is no comprehensive test suite, there are some tests but nothing near complete. So this approach obviously wont help much.
Scott Bennett-McLeish