My project has a complicated maven structure, with lots of sub projects, and 66 pom.xml files. But for my current task, I'm only modifying one resource file, a .xsl file that I need to test lots of small changes. The build takes 9 minutes, and it spends most of its time recompiling my java source files that haven't changed. Is there any way to use maven to package and build my .war file without recompiling my java source code?
-
Possible duplicate: https://stackoverflow.com/questions/13836978/maven-skip-compile – Joachim Rohde Aug 09 '19 at 07:14
-
1Why was this question closed? I wouldn't say that this is too broad. – J Fabian Meier Aug 09 '19 at 08:55
-
I guess you should not run a `clean war`, but a simple `war` - that wouldn't delete all compiled resources. – gaborsch Aug 09 '19 at 09:02
-
Running `mvn war` just gives me `unknown lifecycle phase "war".` Running `mvn war:war` gives me `Error assembling WAR: webxml attribute is required (or pre-existing WEB-INF/web.xml if executing in update mode)` – MiguelMunoz Aug 09 '19 at 20:14
2 Answers
This is a tricky one. Maven is not good at building incrementally.
My first shot would be to try @gaborsch suggestion. But be careful. The results can be inconsistent, depending on your changes. You need to make some experiments to figure out if this works for you.
The second shot would be to speed up the build. You can try to build in parallel, or you can only partly build your multi-module project if only parts are affected (and you are building Snapshot versions).
Gradle is much better at building incrementally (I am a Maven guy, but I have to admit it). But switching to Gradle is probably not the right way to go.

- 33,516
- 10
- 64
- 142
I will suggest what I answer to a similar question.
mvn package -pl my-child-module
This command will build the project my-child-module only.
It won't skip the compilation but at least will skip unwanted modules to be built.
-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

- 3,000
- 19
- 25
-
This didn't help either, but that's probably because I'm not familiar enough with our complicated project structure. But I think this approach has promise. – MiguelMunoz Aug 14 '19 at 20:38