title: Maven Surefire plugin + parallel build
body: <p>In our fairly large project (around 600 maven modules) we've decided to try maven's parallel build capability. So I've installed maven 3.3 and tried to run unit tests.</p>
  
  <p>I've figured out that sometimes our unit tests fail. If I run the module 'alone' it works, and of course if we run maven 'sequentially' (no -T option) it also works.</p>
  
  <p>So, I think that its due to the fact that sometimes tests interfere, probably some static code or shared instances cause these failures. </p>
  
  <p>My question is, what is the optimal way to run the unit tests of my project?
  I'm aware of option to spawn JVM upon each test running, but since we have thousands of unit tests I'm afraid such a build would last forever :)</p>
  
  <p>AFAIK there are 3 possible solutions:</p>
  
  <ol>
  <li><p>Just skip the tests, compile/package/install everything in parallel. And then run tests separately. This approach can be feasible for jenkins, but I can be a hassle for developers who are just accustomed to run <strong>mvn install</strong></p></li>
  <li><p>Somehow extend surefire plugin that it would automatically rerun N times the unit test if it fails. If the test fails, say 50% of times - its really unstable and should cause the whole build failure. I wouldn't like to use a <strong>@RunWith</strong> annotation because of two reasons: a. There are just to many tests to update with this annotation and we don't have a base class or something. b. Some tests already contain this annotation (for power mock for example, or junit rules) </p></li>
  <li><p>Somehow extend surefire plugin to run tests in different classloader. This solution has come to my mind due to the fact that maven seems to run multiple modules with the same classloader (I've just put 2 tests that print the address of classloader in two different submodules and ensured that the classloader is the same, the addresses are identical). This solution looks interesting but relatively complicated.</p></li>
  </ol>
  
  <p>Before diving to any of these solution and talking to my managers, 
  I would appreciate if someone could comment on one of these solutions/provide another one. I Just don't want to reinvent the wheel and hopefully save some time :)</p>
  
  <p>Thanks a lot in advance</p>