2

When I run Maven after changing nothing, maven-compiler-plugin often recompiles Java files; or maven-war-plugin rebuilds or copies a war even though nothing changed; or gwt-maven-plugin builds Google Web Toolkit code (on some computers, not others), even though nothing changed.

How can I see the reason that Maven decides to rebuild something? For example, which files it thinks (incorrectly) have changed?

Here is an example: maven-compiler-plugin is recopying the war resources every time, even when nothing has changed. It is using "exploded" war to save time in development, but this occurs even with regular war.

But my question is more generally how to find out why a Maven goal chooses to rebuild rather than use existing output.

[INFO] Processing war project
[INFO] Copying webapp webResources [d:\dev\proj1/war/WEB-INF] to [d:\dev\proj1\target\proj1-0.0.1-SNAPSHOT]
[INFO]  Copying webapp webResources [d:\dev\proj1/lib/libs] to [d:\dev\proj1\target\proj1-0.0.1-SNAPSHOT]
[INFO]  Copying webapp resources [d:\dev\proj1\war]
 Webapp assembled in [37919 msecs]
Joshua Fox
  • 18,704
  • 23
  • 87
  • 147
  • 1
    Is this a single module project or a multi module project? Which version of the plugins do you use ? – khmarbaise Jun 27 '17 at 12:40
  • 1
    Best would be to a show a log file of your build ...or the project itself... – khmarbaise Jun 27 '17 at 12:41
  • Multimodule. What sort of log? Just Maven output? I added an example above. But my question is more generally how to find out *why* any Maven plugin -- whether GWT, war, compile, or another -- chooses to rebuild rather than use existing output. – Joshua Fox Jun 27 '17 at 17:30
  • You have not answered the question about the versions? Which versions of the plugins do you use ? Which version of Maven do you use? For maven-war-plugin, maven-compile-plugin you can take a look into the source code... – khmarbaise Jun 28 '17 at 08:11
  • maven 3.3.9 jdt.compiler.version 0.24.0 appengine maven plugin 1.3.1 gcloud maven plugin 2.0.9.133.v201611104 versions-maven-plugin 2.3 build-helper-maven-plugin 3.0.0 gwt-maven-plugin 1.6.0 maven-war-plugin 3.1.0 – Joshua Fox Jun 28 '17 at 10:17
  • So you are not using maven-compiler-plugin ? Please show the whole configuration....versions-maven-plugin is not the recent one but that will not change the time...build-helper-maven-pluing ? I see that packaging your war takes 37 seconds...how large is that project? Are you using `mvn clean package`? or do you use `mvn package`only? Running from command line or from Eclipse? – khmarbaise Jun 28 '17 at 10:28
  • > So you are not using maven-compiler-plugin Yes, I am – Joshua Fox Jun 28 '17 at 10:43
  • Running from command line – Joshua Fox Jun 28 '17 at 10:43
  • My question is more general, however. How do plugins detect stateness? See answer below. – Joshua Fox Jun 28 '17 at 10:43
  • If you really want to know the details I recomment to take a look into the source code (The links can be found on the appropriate plugin pages). – khmarbaise Jun 28 '17 at 10:52

1 Answers1

2

Maven plugins have to implement staleness checks by their own (possibly using helpers) and they're free to log the reasons or not, so there's no generic answer (contrary to, say, Gradle). On the whole, Maven incremental build support is rather poor (see https://cwiki.apache.org/confluence/display/MAVEN/Incremental+Builds for instance, which is quite old, but still mostly correct AFAICT), and heavily dependent on each plugin (and their version)

You could try running Maven with debug logs (mvn -X) and dig into the logs. But first try using the latest versions of the plugins. That doesn't mean you'd have your answer as to why the inputs were considered staled, or that it'd fix the observed behavior; but apart from debugging the plugins themselves, there's really no other solution.

Thomas Broyer
  • 64,353
  • 7
  • 91
  • 164