1

概括

默认生命周期<packaging>war</packaging>中的第一阶段是立即调用. process-resourcesmaven-resources-plugin

如何在运行之前执行插件?

我希望有一种简单的方法可以在运行时更改顺序process-resources以让另一个插件先运行。

或者可能强制将早期阶段之一包含在生命周期中,而不是创建自定义生命周期

(实际上我很惊讶war包装没有使用validation,或者initialization因为它们似乎对任何类型的构建都有意义)

细节

我正在尝试使用buildnumber-maven-plugin生成生成${buildNumber}并使用过滤将其保存在 *.properties 文件中,该文件通常作为验证或初始化阶段的一部分运行。所以我尝试将它绑定到process-resources执行阶段,因为它是第一个。

问题是这是在有机会生成maven-resources-plugin之前执行的第一件事。所有其他属性都被过滤得很好。(我知道我可能可以在稍后的步骤中 使用, 或在清单中做一些事情,但这不是我要问的)buildnumber-maven-plugin${buildNumber}maven-war-pluginweb.xml

如果它们不能在流程资源中重新排序,我希望我可以initialization通过现有的某种简单配置强制将阶段包含在生命周期中pom.xml

components.xml也许在定义自定义生命周期时看起来像。

<configuration>
            <phases>
              <initialization>org.codehaus.mojo:buildnumber-maven-plugin:create</initialization>
            </phases>
</configuration>
4

3 回答 3

1

如果 maven 插件绑定了同一个阶段,那么它们按照它们在 pom 中的列表顺序执行, maven-resources-plugin默认情况下绑定到process-resources但它是在超级 pom 中声明的,当你构建时,超级 pom、父 pom 和当前 pom 组成一个pom 称为有效 pom(您可以通过以下方式检查您的有效 pom mvn help:effective-pom

现在来到解决方案,改变插件的执行顺序。

  1. 首先添加buildnumber-maven-plugin并绑定到process-resources
  2. 在下面buildnumber-maven-plugin添加maven-resources-plugin并将其绑定到流程资源

现在,当您构建时,两者都将在process_resources阶段执行,但buildnumber-maven-plugin将在之前执行maven-resources-plugin

于 2013-08-11T02:35:43.563 回答
0

好的,我现在解决了这个问题,感谢@Jaffar Ramay 的回答和他们的评论。

我们可以在创建的 buildNumbermaven-resources-plugin之后再次调用。buildnumber-maven-plugin但是 Jaffar Ramay 的回答对我不起作用,maven-resources-plugin编译并将执行 ID 设置为默认资源,尝试删除额外的执行。

这是我的 pom.xml 希望它可以帮助某人。

<resources>
        <resource>
            <directory>/conf</directory>
            <filtering>true</filtering>
        </resource>
    </resources>
    <pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                    <encoding>UTF-8</encoding>
                    <optimize>true</optimize>
                    <debug>true</debug>
                    <showDeprecation>true</showDeprecation>
                    <showWarnings>true</showWarnings>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>buildnumber-maven-plugin</artifactId>
                <version>1.4</version>
                <executions>
                    <execution>
                        <phase>process-resources</phase>
                        <goals>
                            <goal>create</goal>
                        </goals>
                        <configuration>
                            <doCheck>false</doCheck>
                            <doUpdate>false</doUpdate>
                            <useLastCommittedRevision>true</useLastCommittedRevision>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-resources-plugin</artifactId>
                <executions>
                    <execution>
                        <id>default-resources</id>
                        <phase>compile</phase>
                        <goals>
                            <goal>resources</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${project.build.outputDirectory}</outputDirectory>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
于 2022-01-06T07:59:05.013 回答
-1

请参阅 Maven 生命周期:https ://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html 生命周期参考章节。在 process-resources 之前有几个阶段,例如 generate-resources,您可以使用它来绑定您的插件配置,因此它将<resources>在构建的一部分之前执行。

于 2016-11-14T23:22:43.380 回答