When maven Clean install-dskiptests is done, the size of the xxx.jar in the target directory is different from the size of the xxx.jar installed in the repository.

  • Size of the plug-in in the target directory

  • Size of the plug-in under.m2

In fact, this phenomenon is also confusing at the beginning, the same project, the same command execution, but the size of the two JAR packages is very different. So there are two things that come to mind:

  • Debug Package plug-in execution
  • Understand the Life cycle of Maven plug-ins

Debug Package plug-in execution

This is accomplished with the help of remote debug capabilities in IDEA. At present, there are two projects, one is our main project named MQ-client-Ark-Plugin in the above screenshot, and the other is the source project of packaged plug-in, as shown below:

Step by step, configure remote debug.

1. Run the mvnDebug command to enable the debug mode

Execute mvnDebug install (compile, package, test, deploy, etc.) in the root directory of the main project Mq-client-ark-plugin.

After executing mvnDebug install, you can see that the block listens on port 8000.

2, source code project configuration remote debug

Look for the tools menu in the following image on the main idea screen and select Edit Configurations…

+
Remote

  • Host: remote target host address, because the main project was also started locally, so this is the addresslocalhost
  • Port: Remote Remote enabled by the target hostdebugport
  • Open the remotedebugParameters:-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=8000

After the configuration is complete, run debug to see that the target machine is connected:

Looking at the main project here, the source project is blocked until the debug button above is executed, after which the Maven execution lifecycle begins:

As shown above, execution of sofa- Ark-Maven-plugin is blocked because a breakpoint was made in the source code project.

Find the root cause of the problem from the life cycle of maven execution

Now that you have enabled the debug mode for the source code of the target plug-in, debug the plug-in code. To save space, place the breakpoint directly on the target line:

Analyze the code

  • 1. Access to the projectArtifactAt this time,ArtifactfileTo:
  • 2. ResetFile
  • 3. Resetartifact

If only from the above debug, it is difficult to explain the problem in the beginning. Let’s go back to the Maven execution log for the main project:

The red circles in the figure above represent all the stages maven Install goes through. Maven-plugin = maven-install-plugin = maven-install-plugin = maven-install-plugin

We know that the xxx.jar obtained in the target directory is the product of the packaging phase, while the.m2 is the product of install.

Of course there is no reference to deploy, which is an operation after Install, such as publishing to a remote repository.

Now, because sofa-ark-plugin-maven-plugin replaced the target file before the install plug-in was executed, the package generated in the target directory is inconsistent with the XXX. Jar installed in the local repository.

summary

This article documents a daily troubleshooting process that includes two small points, one is how to debug Maven plug-ins, and the other is a brief understanding of maven’s packaged life cycle.

The code for maven’s packaged lifecycle has not been studied in detail, but it’s safe to assume that Maven has something like a central controller when executing commands, A LifeCycle or Pipeline can be obtained by parsing maven commands (LifeCycle or Pipeline is actually a series of plug-ins assembled). LifeCycle or Pipeline then starts execution, iterating over the plug-in, executing the plug-in’s execute method in turn.