48

I want to run a maven project lifecycle starting, and ending, with the unit tests.

How can I skip recompilation and re-resolution of dependencies and only run the test phase?

jayunit100
  • 17,388
  • 22
  • 92
  • 167

3 Answers3

63

If you start maven by calling a phase it will execute all lifecycle phases up to the one you are calling. For example, when calling

mvn test

all the phases before the test lifecycle phase will be execute too: the project will be validated, sources and resources will be generated and processed, sources will be compiled, the same will happen to test sources and resources and finally unit tests will be run.

But you can also call the plugin goal that is bound to a lifecycle phase. In the case of the test phase the bound goal is surefire's test mojo. So you could call

mvn surefire:test

and no other lifecycle phase will be executed. You can find the goals bound to each phase depending on the package type here.

Akro
  • 1,916
  • 14
  • 11
13

You can run :

mvn surefire:test
Samuel EUSTACHI
  • 3,116
  • 19
  • 24
1

Build your own lifecycle, or run the tests with something besides Maven (Ant, Gradle, your IDE, command-line JUnit runner, ...). That's the kind of restriction you live with when you're using Maven.

Ryan Stewart
  • 126,015
  • 21
  • 180
  • 199
  • Ryan, this is absolutely possible, see the other answers. – Samuel EUSTACHI Feb 14 '13 at 14:39
  • @SamuelEUSTACHI: Yes and no. It's true that I should've thought of mentioning running the surefire plugin explicitly, but the question asks how to run a maven lifecycle composed of only the test phase, which isn't that. – Ryan Stewart Feb 19 '13 at 19:56
  • 2
    Indeed Ryan, the question explicitly mention a lifecycle, so your answer was not wrong. But it might lead jayunit100 in a complicated direction. I was trying to translate the question in basic usage scenario, as a lifecycle of only one phase would be a bit overkill. – Samuel EUSTACHI Feb 20 '13 at 07:29