Maven 插件在构建过程中执行多次

发布于 2024-12-14 01:58:48 字数 955 浏览 5 评论 0原文

我有一个具有多个重叠配置文件的 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>

问题是插件在构建过程中执行多次:

  1. 在构建开始时(在 validate< /代码>阶段)。
  2. jar:jar 执行时。
  3. source:jar 之后 / pre-integration-test (?) 期间,当 Jetty 启动时。

指定 initialize 时会出现类似的结果。有没有办法让它只在构建开始时运行?

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:

  1. At the beginning of the build (during the validate phase).
  2. When jar:jar executes.
  3. After source:jar / during pre-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 技术交流群。

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

发布评论

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

评论(2

意中人 2024-12-21 01:58:48

它执行多次的原因是因为您的一个插件正在执行另一个生命周期作为其魔力的一部分。

source:jar 肯定会这样做,如 其文档

在之前调用生命周期阶段生成源的执行
自行执行。

jar:jar 通常不会,但可能您有另一个插件可以衍生另一个生命周期。

在生成源 jar 的情况下,通常不需要另一个生命周期,插件作者通过实现 jar-no-fork mojo

您可以按照此处描述的步骤将其替换为默认的 jar mojo -> http://maven.apache.org/plugins/maven-source-plugin /usage.html

The 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.

Invokes the execution of the lifecycle phase generate-sources prior to
executing itself.

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

时光清浅 2024-12-21 01:58:48

我在自动化竹制管道上也遇到过类似的问题。我通过在我的 pom.xml 上设置特定的 maven-source-plugin 版本解决了这个问题,

  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-source-plugin</artifactId>
    <version>3.2.1</version>
  </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

  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-source-plugin</artifactId>
    <version>3.2.1</version>
  </plugin>

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.

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