Maven 插件在构建过程中执行多次
我有一个具有多个重叠配置文件的 Maven 项目。我想在每次构建开始时显示活动配置文件。因此,我将以下内容放入 pom.xml
部分:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-help-plugin</artifactId>
<version>2.1.1</version>
<executions>
<execution>
<id>display-active-profiles-at-start-of-build</id>
<phase>validate</phase>
<goals>
<goal>active-profiles</goal>
</goals>
</execution>
</executions>
</plugin>
问题是插件在构建过程中执行多次:
- 在构建开始时(在
validate< /代码>阶段)。
- 当
jar:jar
执行时。 - 在
source:jar
之后 /pre-integration-test
(?) 期间,当 Jetty 启动时。
指定
时会出现类似的结果。有没有办法让它只在构建开始时运行?
I have a Maven project with multiple overlapping profiles. I want to display the active profiles at the beginning of every build. So I put the following into the pom.xml <build>
section:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-help-plugin</artifactId>
<version>2.1.1</version>
<executions>
<execution>
<id>display-active-profiles-at-start-of-build</id>
<phase>validate</phase>
<goals>
<goal>active-profiles</goal>
</goals>
</execution>
</executions>
</plugin>
The problem is that the plugin executes multiple times during the build:
- At the beginning of the build (during the
validate
phase). - When
jar:jar
executes. - After
source:jar
/ duringpre-integration-test
(?), when Jetty is being started.
Similar results when specifying <phase>initialize</phase>
. Is there a way to get this to only run at the beginning of the build?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
它执行多次的原因是因为您的一个插件正在执行另一个生命周期作为其魔力的一部分。
source:jar
肯定会这样做,如 其文档。jar:jar
通常不会,但可能您有另一个插件可以衍生另一个生命周期。在生成源 jar 的情况下,通常不需要另一个生命周期,插件作者通过实现
jar-no-fork
mojo。您可以按照此处描述的步骤将其替换为默认的
jar
mojo -> http://maven.apache.org/plugins/maven-source-plugin /usage.htmlThe reason it executes several times, is because one of your plugins is executing another lifecycle as part of its mojo.
source:jar
definitely does it, as specified by its documentation.jar:jar
usually does not, but it may be that you have another plugin that spins off another lifecycle.In case of generation of source jar, you generally don't need another lifecycle, and plugin authors recognized this by implementing
jar-no-fork
mojo.You may substitute it for default
jar
mojo, by following steps described here -> http://maven.apache.org/plugins/maven-source-plugin/usage.html我在自动化竹制管道上也遇到过类似的问题。我通过在我的 pom.xml 上设置特定的 maven-source-plugin 版本解决了这个问题,
根本原因与我的 Java 版本(Java 8)有关。由于缺少插件定义/版本,显然 maven 会自动选择一个不兼容的 maven-source-plugin 来使用。
I´ve had similar problem on an automated bamboo pipeline. I solved it by setting an specific maven-source-plugin version on my pom.xml
Rootcause was related to my a Java Version (Java 8). Due to the absence of the plugin defintion/version, apparently maven would automatically select an imcompatible maven-source-plugin to use.