我们在生产中使用 MySQL,在单元测试中使用 Derby。我们的 pom.xml 在测试前复制了 Derby 版本的 persistence.xml,并在 prepare-package 阶段将其替换为 MySQL 版本:
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.3</version>
<executions>
<execution>
<id>copy-test-persistence</id>
<phase>process-test-resources</phase>
<configuration>
<tasks>
<!--replace the "proper" persistence.xml with the "test" version-->
<copy
file="${project.build.testOutputDirectory}/META-INF/persistence.xml.test"
tofile="${project.build.outputDirectory}/META-INF/persistence.xml"
overwrite="true" verbose="true" failonerror="true" />
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
<execution>
<id>restore-persistence</id>
<phase>prepare-package</phase>
<configuration>
<tasks>
<!--restore the "proper" persistence.xml-->
<copy
file="${project.build.outputDirectory}/META-INF/persistence.xml.production"
tofile="${project.build.outputDirectory}/META-INF/persistence.xml"
overwrite="true" verbose="true" failonerror="true" />
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
问题是,如果我执行 mvn jetty:run,它将在启动 jetty 之前执行测试 persistence.xml 文件复制任务。我希望它使用部署版本运行。我该如何解决这个问题?
最佳答案
尝试添加参数 -Dmaven.test.skip=true or -DskipTests=true in the command line .例如
mvn -DskipTests=true jetty:run ...
但不确定这是否会跳过流程测试资源阶段。
有关跳过测试的更多信息 is available in the Surefire plugin documentation .
关于java - 如何防止mvn jetty :run from executing test phase?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3044867/