Abstract
Modern software development relies heavily on third-party libraries, often leading to complex dependency trees in multi-module projects. This complexity frequently results in library version inconsistencies, where different modules depend on different versions of the same library, increasing maintenance costs and potentially causing runtime conflicts. We present LibHarmo, an interactive tool designed to detect these inconsistencies and suggest harmonized versions based on an "effort-aware" analysis of API usage. By quantifying the potential code changes required for migration, LibHarmo helps developers overcome the fear of backward incompatibility. Our evaluation of 443 Java Maven projects identified 621 inconsistencies, demonstrating the tool's effectiveness in real-world scenarios.
Introduction
Managing dependencies in large, multi-module projects is a notorious challenge often referred to as "dependency hell." In the Java/Maven ecosystem, the flexibility of dependency declarations allows modules within the same project to inadvertently depend on conflicting versions of the same library. Existing tools like Maven’s enforcer plugin can detect these issues but offer no guidance on how to resolve them. Developers often hesitate to harmonize versions due to the unknown effort required to fix breaking API changes.
Problem: Inconsistency and False Consistency
The research identifies two primary issues in dependency management:
- Library Version Inconsistency (IC): Different modules (e.g., a "core" module and a "web" module) use different versions of the same library. This can lead to unpredictable runtime behavior if both versions end up on the classpath.
- False Consistency (FC): Modules use the same version, but it is hard-coded in multiple separate files rather than managed centrally. This creates a maintenance burden and a high risk of future inconsistency when one module is updated but others are forgotten.
The LibHarmo Approach
To address these challenges, we developed LibHarmo, which follows a three-phase workflow to assist developers in harmonizing their project dependencies.
1. Detection via POM Graph
LibHarmo parses the project's Project Object Model (POM) files to construct an inheritance graph. By resolving all direct dependencies, it identifies both explicit inconsistencies (IC) and "false consistencies" (FC) that lack a single source of truth.
2. Effort-Aware Suggestion
The core innovation of LibHarmo is its ability to quantify migration effort. For each potential harmonized version, the tool performs static analysis using JavaParser and java-callgraph. It counts the number of library APIs currently used by the project that would be deleted or changed in the target version. Developers are then presented with a ranked list of versions, allowing them to choose the "path of least resistance" based on their current release schedule.
3. Automated Refactoring
Once a version is selected, LibHarmo automates the tedious task of updating POM files. It refactors the configuration to use centralized properties. Furthermore, if an API was deleted in the new version, the tool attempts to suggest replacements by scanning Javadoc for migration patterns (e.g., "use [new_api]").
Evaluation and Impact
We evaluated LibHarmo on a dataset of 443 highly-starred Java Maven projects from GitHub. The tool identified 621 library version inconsistencies affecting 34.3% of the projects.
Crucially, the analysis showed that harmonization is often easier than developers fear: on average, fixing an inconsistency affected only 1 deleted API and 12 changed APIs. Real-world validation with developers confirmed the utility of the tool; within a week of reporting, five inconsistencies were officially confirmed as bugs, and one was immediately harmonized by project maintainers.
Conclusion
LibHarmo bridges the gap between detecting dependency issues and resolving them. By providing an interactive, effort-aware recommendation system, it empowers developers to maintain consistent and healthy dependency trees with minimal manual effort. Future work includes extending support to other build systems like Gradle and integrating the tool directly into CI/CD pipelines.
Summary updated