【 background 】
I read a soft article on LinkedIn ,《Managing Software Dependency at Scale》, It describes how LinkedIn handles dependency resolution between modules , And how to better deal with dependencies and dependency management . Feeling in a multi product company , Where products may be interdependent , There should be such a system , To manage and maintain dependencies .
therefore , It took a day to GitHub After I didn't find a project that could work properly on , Decided to refer to the above several existing implementations , Realize a set by yourself .
【 reflection 】
First , Let's talk about why such a system is needed ？
I don't know if you think about it , There could be thousands of modules in one / The company of the product , For cases where there are more interdependencies between modules , How to solve the following problems ：
- Let's put one End of life component removal after , What will be the impact ？
- After the code changes , We should be run Which? dependency Test case ？
- In a deployed system , We end up Which one to use version Module ？
- Whether someone uses High risk version of the library ？
Above questions , The core principle is , Throughout the development cycle of all products , stay Modify a dependency at the same time , It doesn't have any impact on other products .
【 How to save dependencies 】
Before , Consider using key values to keep dependencies on databases and non relational databases , But the effect is not ideal , Finally, the graph database is selected （Neo4J）.
There are three benefits ：
- For any module , Whether or not it depends on other modules , Or be dependent on other modules , Can be very intuitive in the database ;
- For any module , Its dependent subordinate modules and superior modules can be exported quickly ;
- Cross level dependency can be better reflected .
【 Design 】
The code structure is as follows ：
stay Model in ,Dependency mapping pom In the document dependency,Project Mapping products ,Neo4jConn Map database information .
Service in ,GraphBuilder It mainly deals with the interdependence between products and modules ,Neo4JHandler It mainly deals with the specific operations related to the database .
Util Inside ,Finder Inherit SimpleFileVisitor, Handle some path matching work ,PomFileFinder utilize Finder, Look for all pom File and return to the list ,XMLConverter utilize javax.xml Tool class for handling specific xml file .
DependencyManager As an entry point to the entire program , External services .
【 Use 】
First, execute it in the project directory mvn clean install/package pack ;
Then enter target Execute under directory ：
java -jar dependency-manager-0.0.1-SNAPSHOT-jar-with-dependencies.jar D:/workspace/so bolt://localhost:7687 neo4j neo4j Module org.spring*
The first parameter specifies pom File path （ Default recursion to 20 layer , More than cannot be recognized ）;
The second parameter specifies Database url, The third parameter specifies Database user name , The fourth parameter specifies Database password ;
The fifth parameter specifies that Is it the product or the module that exports the dependency , If you specify a module , All modules that meet the conditions will be exported , If you only specify the product , Only the dependencies between all products are exported .
The sixth parameter specifies the conditions the module needs to satisfy , You can specify Prefix , Infix , suffix , Such as spring*, Of all with spring The first bag , This way we can get rid of packages that we don't care about , such as org dependent ,spring Frame related , Our workload can be greatly reduced .
Of course , You can also directly execute ：
java -jar dependency-manager-0.0.1-SNAPSHOT-jar-with-dependencies.jar
Command to get help .
As shown in the figure, the execution is successful ：
【 result 】
The execution result can be in Neo4J View in ：
Red is the product , Brown is the module .
【 Optimize 】
Yes, of course , It's just a little app , There is still a lot of room for growth , After that, there will be several improvements ：
- Dependency Manager UI visualization , The results can be directly displayed to users through the page ;
- Update dependencies automatically ;
- According to the usage of the module, it can automatically issue the warning of circular dependency and abandoned library usage ;
- It can be used across platforms , Not limited to Maven Managed Java project .
Of course , I also hope that those who have the same idea can give their opinions on design , Or read the source code to improve the idea to , It's a great honor .
【 obtain 】
GitHub Address ：https://github.com/liufarui/dependency-manager