Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use plug-ins to resolve Maven dependency conflicts

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

How to use plug-ins to solve Maven dependency conflicts, this article introduces the corresponding analysis and solutions in detail, hoping to help more partners who want to solve this problem to find a more simple and easy way.

1. What is dependency conflict

Maven is an easy to use dependency management tool, but no matter how good it is, it's not perfect. The dependency mechanism of Maven can lead to conflicts of Jar packages.

For example, you now use two Jar packages, An and B, in your project. Now A needs to rely on another Jar package, CJI B, and it also depends on C. But the version of C that A depends on is 1.0, and the version of C that B depends on is 2.0. At this time, Maven will download both 1.0C and 2.0C to your project, so there are different versions of C in your project, and Maven will decide which version of Jar package to use according to the principle of relying on the shortest path first, while another useless Jar package is not used, which is called dependency conflict.

Most of the time, dependency conflicts may not cause any exception to the system, because Maven always chooses a Jar package to use. However, do not rule out that under certain conditions, there will be exceptions similar to the class can not be found, so, as long as there is a dependency conflict, in my opinion, it is best to solve it, do not leave hidden dangers to the system.

2. Solution

The way to resolve dependency conflicts is to use the tag provided by Maven, which needs to be placed inside the tag, such as the following:

Org.apache.logging.log4j

Log4j-core

2.10.0

Log4j-api

Org.apache.logging.log4j

Log4j-core itself depends on log4j-api, but because some other modules also rely on log4j-api, and the two log4j-api versions are different, we use tags to exclude the log4j-api that log4j-core depends on, so that Maven will not download the log4j-api that log4j-core depends on, which ensures that there is only one version of log4j-api in our project.

3 、 Maven Helper

When you see here, you may have a question. How do you know which dependent Jar packages in your project conflict? Maven Helper, a plug-in for InteliJ IDEA, helps us solve this problem. I will not talk about the installation method of the plug-in, since you can Maven, I believe you will also install the plug-in.

After the plug-in is installed, we open the pom.xml file and there is an extra Dependency Analyzer option at the bottom

Img

Click on this option

Img

Find the conflict, right-click, and then select Exclude to exclude conflicting versions of the Jar package.

4. Tips

In addition to using Maven Helper to view dependency conflicts, you can also use the method provided by IDEA-Maven dependency structure diagram, open the Maven window, select Dependencies, and then click on that icon (Show Dependencies) or use the shortcut key (Ctrl+Alt+Shift+U) to open the Maven dependency structure diagram.

Img

In the figure, we can see that there are some red solid lines, these red solid lines are dependency conflicts, and blue solid lines are normal dependencies.

This is the answer to the question about how to use plug-ins to solve Maven dependency conflicts. I hope the above content can be of some help to you. If you still have a lot of doubts to be solved, you can follow the industry information channel to learn more about it.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report