【问题标题】:Maven : how to order multiple execution of a goal in the same phase in a specfic orderMaven:如何在同一阶段以特定顺序对目标的多次执行进行排序
【发布时间】:2018-11-13 19:41:19
【问题描述】:

我希望我的“预集成测试”阶段是以下目标的执行,按照这个特定的顺序。

PHASE : 预集成测试

  • 获取一个 spring boot jar (maven-dependency-plugin:copy)
  • get-a-port (build-helper-maven-plugin:reserve-network-port)
  • 显示端口(maven-antrun-plugin:run #1)
  • 启动服务器(exec-maven-plugin)
  • 等待启动(maven-antrun-plugin:run #2)

有没有办法使用 Maven 3 来做到这一点?

我面临的问题是 "maven-antrun-plugin:run" 1 & 2 将始终一个接一个地运行,因为它们是在同一个插件元素中定义的:

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-antrun-plugin</artifactId>
                <version>1.8</version>
                <executions>
                    <execution>
                        <id>display-port</id>
                        <phase>pre-integration-test</phase>
                        <goals>
                            <goal>run</goal>
                        </goals>
                        <configuration>
                            <target>
                                <echo>Displaying value of 'tomcat.http.port' property</echo>
                                <echo>[tomcat.http.port] ${tomcat.http.port}</echo>
                            </target>
                        </configuration>
                    </execution>
                    <execution>
                        <id>wait-for-startup</id>
                        <phase>pre-integration-test</phase>
                        <configuration>
                            <target>
                                <sleep seconds="10" />
                            </target>
                        </configuration>
                        <goals>
                            <goal>run</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

现在,我发现这样做的唯一方法是在 pom 文件中复制“maven-antrun-plugin:”插件元素。 但这给了我一个警告

'build.plugins.plugin.(groupId:artifactId)' must be unique but found duplicate declaration

对于这个问题的范围,我不是在寻找解决方法,例如更改“显示端口”或“等待启动”的插件,或者更改目标的阶段。

我只是想了解我正在尝试做的事情是否可行。

【问题讨论】:

  • 与tomcat/display port相关的Spring Boot需要做哪些测试?此外,您知道 spring-boot-maven-plugin:run 吗?我不明白你为什么要这样做dependency:copy
  • 无论我想做什么,问题都是关于 Maven 订购。我引用自己的话:“对于这个问题的范围,我不是在寻找解决方法,例如更改“显示端口”或“等待启动”的插件,或者更改目标。”

标签: maven maven-3


【解决方案1】:

如果多个执行具有相同的阶段,那么第一个执行将是内置的(例如maven-compiler-plugin),其id是default-something,然后其他执行将按顺序进行它们出现在你的 pom 文件中。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-01-26
    • 2011-07-04
    • 2015-06-30
    • 2020-05-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多