Recent study plug-in mechanism sofa-ark, and found that after executing maven clean install -DskipTests
when playing in the target directory xxx.jar
and install to a local warehouse xxx.jar
inconsistent size.
Plug-in target directory size
Plug size under .m2
In fact, this phenomenon is also beginning to see a muddled force, the same project, same command, but to get two huge jar package size gap. So for this issue, I think there are two points:
debug plug-packaging process execution
Understand the life cycle maven plugin
01 debug plug-packaged implementation process
Here it needs the ability to remotely debug IDEA is done. There are two engineering, a construction is our primary, mq-client-ark-plugin project called the screenshot above, and the other widget is packaged source project, as shown below:
Then the following step by step to complete remote debug
configuration.
(1) using the command to turn debug mode mvnDebug
In the main works mq-client-ark-plugin
performed under the root directory mvnDebug install
(except, of course install
outside may be compile
, package
, test
, deploy
etc.).
When performing complete mvnDebug install
, you can see the listening port 8000 blocked up.
(2) Source project to configure the remote debug
In idea
under the Tools menu of the main screen of FIG find, selectEdit Configurations...
After opening the configuration panel, the upper left corner +
selectRemote
Fill in the relevant remote debug parameters
Host
: Remote target host address, because before the main project is launched locally, so this islocalhost
Port
: Remote remote target host opendebug
portOpen the Remote
debug
parameters:-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=8000
配置完成之后,执行 debug
,可以看下已经连接到了目标机器:
在来看主工程这里,在源码工程没有执行上面的 debug
按钮之前,一直都是阻塞的,执行之后 maven
执行的生命周期开始了:
如上图,因为在源码工程中打了断点,所以当执行到 sofa-ark-maven-plugin
插件时阻塞了。
02 从 maven 执行的生命周期找出问题根源
上面已经搞定了对目标插件源码的 debug
模式的开启,那么下面就是对插件代码进行 debug
操作。节省篇幅,这里直接将断点放在目标代码行位置:
分析这段代码
1、获取到项目的
Artifact
,此时Artifact
的file
为:2、重新设置的
File
3、重新设置了
artifact
如果单从上面 debug
来看,其实很难解释开篇的那个问题。那么这里在回过头来看下 主工程的 maven
执行日志:
如上图中圈红的部分,代表 maven install
所经历的所有阶段。可以看到 sofa-ark-plugin-maven-plugin
是在 maven-install-plugin
后面,那这意味着什么呢?
我们知道在 target 目录下得到的 xxx.jar 是打包阶段的产物,而 .m2 下面的是 install 的产物。
当然这里没有涉及到
deploy
,deploy
是install
之后的操作,比如发布到远程仓库。
现在再来看,因为 sofa-ark-plugin-maven-plugin
在执行 install
插件之前将 目标文件给替换了,所以导致打包生成的 target
目录下的 xxx.jar
和 安装到本地仓库的 xxx.jar
不一致。
03 小结
This article documents a routine troubleshooting process, including two small points, one is how to debug maven plugin, the other is simple to understand maven package lifecycle.