我能否从任意阶段恢复Maven生命周期?

11
我想说服Maven“从上次结束的地方”继续。我首先运行mvn package来构建软件包。稍后我可能想继续整个生命周期执行集成测试等操作,通过运行mvn install。在这种情况下,我希望Maven不从头开始启动生命周期,而是实际上在package之后的第一个阶段(即pre-integration-test)恢复。是否可以在非第一阶段开始生命周期?

1
我认为你做不到这件事。另见此邮件 - Tunaki
我知道mvn install在进行“install”之前会执行“validate”,“compile”,“package”和“verify”,因此,实际上我不知道是否可能覆盖这个设置,因为重写这个设置应该是唯一的方法。 - RudiDudi
1个回答

2
据我所知,目前没有内置的功能支持此操作。不过,您可以采取以下措施:
覆盖所有目标绑定,包括但不限于来自以下内容的预期起始阶段(但排除)的绑定:
  • default-bindings.xml
  • 当前和所有父POM的<build>/<plugins>/<plugin>部分 (使用mvn help:effective-pom进行检查)
配置文件中进行设置:
<profiles>
    <profile>
        <id>resume-at-pre-int-test</id>
        <build>
            <plugins>
                <plugin>
                    <groupId>com.soebes.maven.plugins</groupId>
                    <artifactId>maven-echo-plugin</artifactId>
                    <version>0.1</version>
                    <executions>
                        <execution>
                            <id>skip-process-resources</id>
                            <phase>process-resources</phase>
                            <goals>
                                <goal>echo</goal>
                            </goals>
                        </execution>
                    </executions>
                    <configuration>
                        <echos>
                            <echo>Default plugin:goal binding for process-resources phase overridden</echo>
                        </echos>
                    </configuration>
                </plugin>

                <plugin>
                    ...
                </plugin>

                ...

            </plugins>
        </build>
    </profile>
</profiles>

使用mvn install -P resume-at-pre-int-test命令来启动它。


我能否只解除目标绑定? - Rinke
@Rinke 我没有意识到这一点。 - Gerold Broser
@Rinke 只是一个想法:根据这个答案,您可以尝试相应地调整 <您的 Maven 安装>/lib/maven-core-x.y.z.jar/META-INF/plexus/default-bindings.xml,但我自己还没有尝试过。 - Gerold Broser

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接