Search code examples
javamavencompilationwar

Maven build war some classes not included


When building maven webapp by using mvn install or mvn compile war:war on two different machines resulting WAR files have 20MB difference and their build times are 1 and a half minutes apart (30s vs 2min)

By inspecting war files using WinRAR I've noticed that smaller WAR does not contain WEB-INF\classes\WEB-INF and WEB-INF\classes\resource folders.

The whole codebase is the same. POM.xml contains maven-compiler-plugin, webapp and unit tests run well on both apps with difference that smaller WAR seems to not have included properties files for language locality.


Solution

  • Most likely one of the machines stores corrupted artifacts in the local maven repository or points to a mirror server with broken artifacts. When artifact has invalid pom.xml or parent's pom.xml can't be resolved you will get a warning:

    The POM for is invalid, transitive dependencies (if any) will not be available

    Inspect the console output and confirm there are no such warnings. See this answer for further reading.

    It also could be Maven version used differs on both machines. This could result in Maven War Plugin running in different versions, one of them could be affected by a bug. Ensure that both builds use the same Maven version and configuration e.g. with Maven Wrapper.

    There is also a chance that you have a non standard build with modules being bound manually to phases e.g. Maven Assembly Plugin bound to test phase. Ensure that both machines build the artifact with exactly the same command.

    Above generally illustrates why one should have a CI server to get reproducible builds.