Alden
Alden

Reputation: 6703

Maven multi module project lifecycle

I have a large multi module maven project and am using the compiler, surefire and failsafe plugins. All of my unit tests run with surefire, and my integration tests with failsafe. Why running mvn verify on the whole project, it appears to do the following:

  1. Get the next module to run (based on dependency graph)
  2. Execute the full lifecycle for that module (initialize, compile, test, integration-test, ...)
  3. Repeat until no more modules

This is a really slow process and I feel like it would be faster if it did the following:

  1. Compile all modules
  2. Run unit tests on all modules
  3. Run integration tests on all modules

Effectively doing something like:

  1. Execute the current phase for all modules
  2. Move to the next phase, repeat

However I can't figure out how to set this up. Is this possible? Or is my hypothesis that this might be faster off? Thanks for the help.

Upvotes: 1

Views: 1202

Answers (1)

Jigar Joshi
Jigar Joshi

Reputation: 240890

You can't do that, consider following structure

A (pom)
|
|
|
|
------B (jar)
|     \---C (dependency) 
|
|------C (jar)

here B depends on C, now you for example you have following classes in B & C respectively

B

class B{
 C c;
 public void sayHello(){
    c.sayHello();
 }
}

C

class C {
  public void sayHello(){}
 }

now you change C class to

 class C {
  public void sayHello(String name){}
 }

and if you do compile on all phase it will start from A - C - B (dependency graph), C compiled fine (compile just compiles source and copies classes to target/classes), now you are running compile on B it will compile fine because it will take B's older version from local maven cache (where it still has method without any param)

now install happens on C first and on B it will go SUCCESSFUL

next attempts of the same thing will fail, because B will now find different method signature

What would be effective here is incremental build, however maven doesn't quite support incremental build in true sense, see here is the open request for that

if you want just test executions saperate from build life cycle you can do it using separate build profile

Upvotes: 1

Related Questions