Interactive, Effort-Aware Library Version Harmonization

Kaifeng Huang, Bihuan Chen, Bowen Shi, Ying Wang, Congying Xu, Xin Peng

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:

  1. 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.
  2. 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.
Figure 1: POM inheritance graph illustrating how dependencies are resolved across multiple modules and identifying potential inconsistencies.

The LibHarmo Approach

To address these challenges, we developed LibHarmo, which follows a three-phase workflow to assist developers in harmonizing their project dependencies.

Figure 2: The LibHarmo workflow, spanning from project repository analysis to automated POM refactoring.

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

Abstract

As a mixed result of intensive dependency on third-party libraries, flexible mechanism to declare dependencies, and increased number of modules in a project, multiple versions of the same third-party library are directly depended in different modules of a project. Such library version inconsistencies can increase dependency maintenance cost, or even lead to dependency conflicts when modules are inter-dependent. Although automated build tools (e.g., Maven's enforcer plugin) provide partial support to detect library version inconsistencies, they do not provide any support to harmonize inconsistent library versions. We first conduct a survey with 131 Java developers from GitHub to retrieve first-hand information about the root causes, detection methods, reasons for fixing or not fixing, fixing strategies, fixing efforts, and tool expectations on library version inconsistencies. Then, based on the insights from our survey, we propose LibHarmo, an interactive, effort-aware library version harmonization technique, to detect library version inconsistencies, interactively suggest a harmonized version with the least harmonization efforts based on library API usage analysis, and refactor build configuration files. LibHarmo is currently developed for Java Maven projects. Our experimental study on 443 highly-starred Java Maven projects from GitHub indicates that i) LibHarmo identifies 621 library version inconsistencies covering 152 (34.3%) of projects, and ii) the average harmonization efforts are that 1 and 12 library API calls are affected, respectively due to the deleted and changed library APIs in the harmonized version. 5 library version inconsistencies have been confirmed, and 1 of them has been already harmonized by developers.
BibTeX
@inproceedings{huang2020interactive,
  author = {Kaifeng Huang and Bihuan Chen and Bowen Shi and Ying Wang and Congying Xu and Xin Peng},
  title = {{Interactive, Effort-Aware Library Version Harmonization}},
  booktitle = {ESEC/SIGSOFT FSE},
  year = {2020},
  url = {https://openreview.net/forum?id=W0xg7oRaBHY},
}
Figure