This article is part of the Maven source Code Parsing series: How does dependency mediation work? The second part introduces how to debug Maven source code and plug-in source code.
Please read the rest of the series, in order, at juejin.cn/post/703292…
The body of the
With the source package and the Demo project, we are ready to start analyzing. The problem is that we’re not familiar with Maven’s source code, so we can’t dive into it. So, let’s analyze it in a debugging way, simple and accurate.
So the question is, how to debug MVN source and plug-in source? Here’s a very simple way to do it: use the mvnDebug command to aid in debugging. Taking our Demo project as an example, the steps are as follows:
- In the Demo project terminal, type mvnDebug XXX (XXX can be any command, such as clean, compile, or Dependency :tree). In short, where MVN was used, mvnDebug is now used. After executing the command, you should see that listening mode is started (as shown below). So we need to start the Maven source in debug mode to keep the process going.
- Open the apache-Maven-3.6.3 project and create a new remote debug configuration with port 8000. As shown in the figure below.
- Start The Maven source in debug mode (you can make a breakpoint at the entry point) and see the flow come in. As shown in the figure below.
- Then we can have fun debugging.
Note 1: This article introduces the debugging process using Maven core source code as an example. In fact, the debugging method of Maven plug-in source code is exactly the same. Note 2: This method of debugging is very flexible, we can choose different business projects and coordinate with Maven source code. There are of course many ways to debug Maven’s source code, but there are a lot of things to set up. Why not use the built-in mvnDebug tool, easy and convenient.
Now that we know how to debug Maven and the plug-in source code, we can begin the formal analysis.