上一个问题的后续: Maven run class before test phase: exec-maven-plugin exec:java not execution class。
我在詹金斯盒子上运行 jUnit4 测试,用 maven 构建。在构建的测试阶段之前,我需要运行一个特定的 main-method java 程序。目的是在测试运行之前恢复测试数据库。
如果我运行分配给这个 exec 的确切阶段,我的类将按预期执行;但是当我运行整个构建时,我的类没有执行:
具体来说,它运行:
mvn -X exec:java generate-test-resources
但不运行:
mvn -X -e install
--或--
mvn -X -e clean install
pom.xml: 我的 pom.xml 文件包括:
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.3</version>
<executions>
<execution>
<id>build-test-environment</id>
<phase>generate-test-resources</phase>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<mainClass>main.java._tools.BuildTestEnvironment</mainClass>
</configuration>
</plugin>
</plugins>
</pluginManagement>
生命周期默认值: 我没有对 maven 的生命周期感到厌烦。日志将其报告为:
[DEBUG] Lifecycle default -> [
validate,
initialize,
generate-sources,
process-sources,
generate-resources,
process-resources,
compile,
process-classes,
generate-test-sources,
process-test-sources,
generate-test-resources,
process-test-resources,
test-compile,
process-test-classes,
test,
prepare-package,
package,
pre-integration-test,
integration-test,
post-integration-test,
verify,
install,
deploy
]