确定插件中的Maven执行阶段 [英] Determining Maven execution phase within a plugin
问题描述
我有一个可转换已编译类的插件.需要对模块的类和模块的测试类都进行此转换.因此,我将插件绑定到流程类和流程测试类两个阶段.我遇到的问题是,我需要确定插件当前正在哪个阶段执行,因为我(实际上)不能两次变换同一组类.
I have a plugin which transforms the compiled classes. This transformation needs to be done for both the module's classes and the module's test classes. Thus, I bind the plugin to both the process-classes and process-test-classes phases. The problem I have is that I need to determine which phase the plugin is currently executing in, as I do not (cannot, actually) transform the same set of classes twice.
因此,在插件中,我需要知道我是否正在执行流程类-在这种情况下,我需要转换模块的类.或者,如果我正在执行流程测试类-在这种情况下,我不会转换模块的类,而不会转换模块的测试类.
Thus, within the plugin, I would need to know if I'm executing process-classes - in which case I transform the module's classes. Or if I'm executing process-test-classes - in which I case I do not transform the module's classes and transform only the module's test classes.
我当然可以为此创建两个插件,但是这种解决方案极大地冒犯了我的敏感性,并且在某些州可能是违法的.
I could, of course, create two plugins for this, but this kind of solution deeply offends my sensibilities and is probably against the law in several states.
看来我可以从模块中获得的信息应该能够告诉我当前阶段是什么.我只是无法终生发现那是什么东西.
It seems like something I could reach from my module should be able to tell me what the current phase is. I just can't for the life of me find out what that something is.
谢谢...
推荐答案
因此,在插件中,我需要知道我是在执行流程类(...)还是在执行流程测试类
Thus, within the plugin, I would need to know if I'm executing process-classes (...) or if I'm executing process-test-classes
AFAIK,这不太可能.
我当然可以为此创建两个插件,但是这种解决方案严重冒犯了我的敏感性,并且在某些州可能违反了法律.
I could, of course, create two plugins for this, but this kind of solution deeply offends my sensibilities and is probably against the law in several states.
我没有看到两个Mojos共享代码但绑定到不同阶段有什么错.类似于Maven编译器插件(及其compiler:compile
和compiler:testCompile
目标).
I don't see anything wrong with having two Mojos sharing code but bound to different phases. Something like the Maven Compiler Plugin (and its compiler:compile
and compiler:testCompile
goals).
这篇关于确定插件中的Maven执行阶段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!