This article is part of the Maven source Code Parsing series: How does dependency mediation work? The seventh and last chapter is mainly a summary.
Please read the rest of the series, in order, at juejin.cn/post/703292…
conclusion
In this series of articles, we have built a simple multi-module project that, in the form of an experiment, parses the four dependency tuning principles from a source code perspective. It involves two mediation principles of transfer dependency, an override principle within the same file, and the dependencyManagement locking principle. Among them, the two mediation principles of transfer dependency are related to Nest ConflictResolver. The overriding principle in the same file is the simplest: simple Map overriding. Finally, the dependencyManagement dependency locking principle is a bit more complicated because it involves resolution of dependencyManagement versions, and the resolved version number prevails.
In real work, these dependencies may coexist. DependencyManagement version locking is very popular in large projects, if you can understand how it works from a source perspective, you will improve your ability to use Maven.
resources
The source code used in this article has been uploaded to Github at github.com/xiaoxi666/m… , need partners please download by yourself.
What have we learned from reading the source code?
First, we learned how Maven’s dependency mediation implementation works, so we’ll be able to keep track of the output. A little more broadly, the core principles of dependency management tools are the same: managing dependency versions. Hopefully, this article has given you some insight into how to implement package management tools.
Then there are design considerations. Maven provides the core implementation and reserves various extension points that allow different plug-ins to implement different functions. This development mode can be very convenient function expansion, for the growth of a software is very beneficial. There are many products developed along these lines, such as the familiar Atom.
When it comes to algorithms, they are classic recursive algorithms and the oft-mentioned memos (maps store resolved dependencies).
Finally, talk about the embodiment of design patterns. There are several sources mentioned above, such as template patterns (implementations of different conflict mediators), visitor patterns (see the visit method), observer patterns (various listeners, which print information when events are generated), and bridge patterns (dependency: Tree implementation is a bridge, Slf4j similar schema) and so on.
Of course, you also learned a simple and convenient way to debug Maven source code.
reference
Maven’s official website: maven.apache.org/guides