如果我在 中定义一个插件 标签并想在我的站点命令中使用它,我该怎么做? 我是否必须在 中定义插件? 再次标记?
我可能已经在构建标签中完成并且也想在报告标签中进行的配置怎么样? (例如,我不想两次指定配置文件的位置,只是为了在两个生命周期中使用插件)
例如:我在构建标签中定义我的 checkstyle 插件,并为要使用的规则配置自定义位置。 我这样做是因为规则打包在一个 jar 中,所以我可以将其定义为依赖项。 如果我在报告标签中执行此操作,这是不可能的。 但我还需要在报告标签中使用这个插件,以便 surfire 可以为 checkstyle 生成报告。 所以我还必须在报告标签中定义插件。
也许我在这里做的事情完全错误,但我不知道除此之外我还能做什么。 我不喜欢的是我的 pom 中有两次 1 个插件(在构建标签和报告标签中)。
我希望有人可以验证我的解决方案是否正确,或者给我建议如何做得更好。
谢谢
库库
If i define a plugin in the <build> tag and want to use this in my site command how do i do that? Do i have to define the plugin within <reporting> tag again?
And how about the configuration which i probably have done within the build tag and want to take place at the reporting tag as well? (i dont want to specifie for example a location of a configuration file twice just to use a plugin in 2 lifecycles)
As example: I define my checkstyle plugin in the build tag and configrue a custom location for the rules to be used. I do that because the rules are packed in a jar so i can define it as dependency. This would not be possible if i do it in the reporting tag. But i need to use this plugin in the reporting tag aswell so surfire can generate a report for checkstyle. So i have to define the plugin within the reporting tag aswell.
Maybe i'm doing something complete wrong here but i don't see how i can do it other then that. What i dont like is that i have 1 plugin twice in my pom (in the build tag and reporting tag).
I hope somebody can verify my solution is ok, or give me an advise how to do it better.
thx
kuku
发布评论
评论(2)
Maven 插件通常在您定义它时绑定到给定生命周期阶段的执行。 插件本身指定了这是哪个生命周期阶段,但如果您有特殊需要,您可以更改它。
如果您有一个多模块构建,您可以定义一组插件,其中包含公共父 pom 中所需的所有参数。 这通常会针对构建中的每个子模块执行。 如果您不希望这种情况发生,您可以这样定义它(在父 pom 中):
如果您在一个或多个嵌套模块中想要启用此插件,您可以只说:
在该特定模块中。 您可以选择是否要重新配置从父定义继承的默认参数。
我想这就是你要找的?
A maven plugin is typically bound to execution in a given lifecycle phase when you define it. The plugin itself specifies which lifecycle phase this is, but you can change this if you have special needs.
If you have a multi-module build you can define a set of plugins with all parameters required in a common parent-pom. This will normally be executed for every sub-module in the build. If you do not want this to happen you can define it (in the parent pom) like this:
If you in one or more nested moudules want to enable this plugin you can just say:
In that specific module. You can choose if you want to reconfigure the default parameters which are inherited from the parent definition or not.
I think this is what you're looking for ?
除了 KRosenvold 的答案之外,您还可以通过在
部分声明插件来最小化配置,也许在您的 继承链中最顶层的pom,然后就可以 省略在声明使用插件的所有其他地方指定插件的版本。父 Pom:
子 Pom:
In addition to KRosenvold's answer, you can also minimize configuration by declaring a plugin in the
<pluginManagment>
section, perhaps at your topmost pom in the inheritance chain, and then you can omit specifying the version of the plugin in all the other places you are declaring it's use.Parent Pom:
Child Pom: