Now I run it again (...) Maven executes unit tests and static code analysis again
Because that's simply what you're asking Maven to do.
When you call a build phase, Maven will execute not only that build phase, but also every build phase prior to the called build phase. Thus, invoking:
mvn install
will run every build phase preceding install
(validate
, compile
, test
, package
, etc), before executing install
and also the plugins you bound to these phases.
And while Maven does support incremental compilation of Java sources, other plugins are not that smart and will be fired again.
Now, some remarks/suggestions:
- what's the point of running
install
if you didn't change anything?
- if you don't want to run static code analysis at each build, use a special profile.
A multi-module project, with extensive testing and static code analysis. I run mvn clean install
, then I change one single java file in one module. Then I run mvn install
and expect maven to test/analyze only this particular module, which was changed. Unfortunately, it re-tests and re-analyzes all modules.
Indeed, if you run mvn install
as part of a reactor build, will run mvn install
on all modules and tests and analysis will go again on all modules. That's maybe not what you expect, but that's what you'll get (AFAIK, static analysis plugin are not aware of changes - I'm not able to explain why things aren't better).
It takes so much time.
I suggest to use the advanced reactor options to only build a subset of the modules. These options are:
-rf, --resume-from
Resume reactor from specified project
-pl, --projects
Build specified reactor projects instead of all projects
-am, --also-make
If project list is specified, also build projects required by the list
-amd, --also-make-dependents
If project list is specified, also build projects that depend on projects on the list
So in your case, you could run something like (assuming you touched module-foo
):
mvn -pl module-foo,my-packaged-app install
or, to rebuild all projects that depend on module-foo
:
mvn -pl module-foo -amd install