Maven 2 插件,构建 + 万无一失

发布于 2024-07-13 03:50:51 字数 528 浏览 15 评论 0 原文

如果我在 中定义一个插件 标签并想在我的站点命令中使用它,我该怎么做? 我是否必须在 中定义插件? 再次标记?

我可能已经在构建标签中完成并且也想在报告标签中进行的配置怎么样? (例如,我不想两次指定配置文件的位置,只是为了在两个生命周期中使用插件)

例如:我在构建标签中定义我的 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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

人事已非 2024-07-20 03:50:51

Maven 插件通常在您定义它时绑定到给定生命周期阶段的执行。 插件本身指定了这是哪个生命周期阶段,但如果您有特殊需要,您可以更改它。

如果您有一个多模块构建,您可以定义一组插件,其中包含公共父 pom 中所需的所有参数。 这通常会针对构建中的每个子模块执行。 如果您不希望这种情况发生,您可以这样定义它(在父 pom 中):

<plugin>
   <artifactId>maven-surefire-plugin</artifactId>
       <configuration>
            <skip>true</skip>
       </configuration>
   ... More plugin cofniguration stuff ...
 </plugin>

如果您在一个或多个嵌套模块中想要启用此插件,您可以只说:

<plugin>
   <artifactId>maven-surefire-plugin</artifactId>
       <configuration>
            <skip>false</skip>
       </configuration>
   ... Maybe Configuration ....
 </plugin>

在该特定模块中。 您可以选择是否要重新配置从父定义继承的默认参数。

我想这就是你要找的?

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:

<plugin>
   <artifactId>maven-surefire-plugin</artifactId>
       <configuration>
            <skip>true</skip>
       </configuration>
   ... More plugin cofniguration stuff ...
 </plugin>

If you in one or more nested moudules want to enable this plugin you can just say:

<plugin>
   <artifactId>maven-surefire-plugin</artifactId>
       <configuration>
            <skip>false</skip>
       </configuration>
   ... Maybe Configuration ....
 </plugin>

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 ?

安人多梦 2024-07-20 03:50:51

除了 KRosenvold 的答案之外,您还可以通过在 部分声明插件来最小化配置,也许在您的 继承链中最顶层的pom,然后就可以 省略在声明使用插件的所有其他地方指定插件的版本

父 Pom:

<pluginManagement>
    <plugins>
        <plugin>
            <artifactId>maven-assembly-plugin</artifactId>
            <version>2.2-beta-1</version>
        </plugin>
    </plugins>
<pluginManagement>

子 Pom:

<plugins>
    <plugin>
        <artifactId>maven-assembly-plugin</artifactId>
    </plugin>
</plugins>

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:

<pluginManagement>
    <plugins>
        <plugin>
            <artifactId>maven-assembly-plugin</artifactId>
            <version>2.2-beta-1</version>
        </plugin>
    </plugins>
<pluginManagement>

Child Pom:

<plugins>
    <plugin>
        <artifactId>maven-assembly-plugin</artifactId>
    </plugin>
</plugins>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文