How to get the current MavenSession or MavenExecutionRequest from a Plexus Component

拈花ヽ惹草 提交于 2019-12-03 09:17:18

I don't believe there is, nor would I think it's a good idea.

From my understanding, what you're aiming to achieve is have a commons-like component, that will be used for several mojos. This requires the current Maven session to be passed in & used to subsequently pass back a value.

The way Maven works however, is that it runs goals from plugins in an almost container-like environment. Each plugin is allowed to act within a particular Maven Phase, as defined by the <executions />. This allows Maven to separate the complexities of building, testing, checking, deploying etc. etc. Calling mvn clean install, unless I'm mistake, is two separate executions, one to run the clean build lifecycle, followed by the install.

It is therefore not safe to assume that the MavenSession and subsequent MavenExecutionRequest represent the same instance used in a previous call. clean is a separate call, whose logic shouldn't be maintained in a new session.

So, what I'm essentially saying, is that whilst having a common plexus component is a good practice, particularly to maintain consistency across your mojos, it is right practice (almost ioc), to provide the appropriate session each time.

I hope that's the answer you're looking for. Rather long, but to understand why you need to provide the session, think Maven.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!