How to prevent mvn jetty: run from the testing phase?

We use MySQL in production and Derby for unit tests. Our pom.xml copies the Derby version of persistence.xml before testing and replaces it with the MySQL version at the package preparation stage:

<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> 

The problem is that if I run mvn jetty: run, it will complete the task of checking the persistence.xml test before launching the berth. I want it to run using the deployment version. How can i fix this?

+4
source share
2 answers

The jetty:run target causes the test-compile life cycle phase to complete before it jetty:run . Therefore, skipping tests will not change anything.

What you need to do is bind the execution of copy-test-persistence to the lifecycle phase behind test-compile , but before test . And there are not a dozen candidates, but only one: process-test-classes .

This conceptually may not be perfect, but it is the least worst option and it will work:

  <plugin> <artifactId>maven-antrun-plugin</artifactId> <version>1.3</version> <executions> <execution> <id>copy-test-persistence</id> <phase>process-test-classes</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> ... </executions> </plugin> 
+2
source

Try adding arguments - Dmaven.test.skip = true or -DskipTests = true on the command line . for instance

 mvn -DskipTests=true jetty:run ... 

Not sure if this is missing the process-test-resource phase.

Additional information on missed tests is available in the Surefire plugin documentation .

+5
source

Source: https://habr.com/ru/post/1312864/


All Articles