FIXED: this is a known bug in maven-compiler-plugin 3.1
I am converting an ant-based build of a 1000+ java-sources project to maven. So far so good, but every time launch mvn compile it recompiles everything (instead of reusing old classes)
(only for files in a certain package, which is possibly unreferenced from the rest of the code; not my sources, I am just trying to mavenize the build)
Compilation does not fail, and classes with updated timestamps are being generated at
However, when looking at timestamps, the java files have not changed since yesterday, and the class files are current. Why are these sources determined to be stale? How can I debug this issue?.
It is a drag to have to recompile 1k+ files even when no changes have occurred...
Sample output:
$ mvn clean compile [INFO]Scanningfor projects...[INFO][INFO]------------------------------------------------------------------------[INFO]BuildingMyProject1.9.0-SNAPSHOT [INFO]------------------------------------------------------------------------[WARNING]The POM for net.sourceforge:jffmpeg:jar:1.1.0is missing,no dependency information available [INFO][INFO]--- maven-clean-plugin:2.4.1:clean (default-clean)@my-project ---[INFO]Deleting/project_path/target [INFO][INFO]--- maven-resources-plugin:2.5:resources (default-resources)@my-project ---[debug] execute contextualize [INFO]Using'UTF-8' encoding to copy filtered resources.[INFO] skip non existing resourceDirectory /project_path/src/main/resources [INFO][INFO]--- maven-compiler-plugin:3.1:compile (default-compile)@my-project ---[INFO]Changes detected - recompiling the module![INFO]Compiling1162 source files to project_path/target/classes ....[INFO]------------------------------------------------------------------------[INFO] BUILD SUCCESS [INFO]------------------------------------------------------------------------[INFO]Total time:11.215s[INFO]Finished at:TueJul3012:42:25 CEST 2013[INFO]FinalMemory:25M/429M[INFO]------------------------------------------------------------------------ $ mvn compile [INFO]Scanningfor projects...[INFO][INFO]------------------------------------------------------------------------[INFO]BuildingMyProject1.9.0-SNAPSHOT [INFO]------------------------------------------------------------------------[WARNING]The POM for net.sourceforge:jffmpeg:jar:1.1.0is missing,no dependency information available [INFO][INFO]--- maven-resources-plugin:2.5:resources (default-resources)@my-project ---[debug] execute contextualize [INFO]Using'UTF-8' encoding to copy filtered resources.[INFO] skip non existing resourceDirectory /project_path/src/main/resources [INFO][INFO]--- maven-compiler-plugin:3.1:compile (default-compile)@my-project ---[INFO]Changes detected - recompiling the module![INFO]Compiling1162 source files to /project_path/target/classes ...[INFO]------------------------------------------------------------------------[INFO] BUILD SUCCESS [INFO]------------------------------------------------------------------------[INFO]Total time:12.140s[INFO]Finished at:TueJul3012:42:44 CEST 2013[INFO]FinalMemory:22M/379M[INFO]------------------------------------------------------------------------
After testing further, going back to 3.0 did not actually fix the problem (it only works until the next mvn clean compile. However, as Michael Lemke suggests in comments, marking useIncrementalCompilation to false is a workable substitute; now, only the offending package gets recompiled each time (instead of the whole code-base).
回答2:
My situation was slightly different, so I'm just adding this in case someone else has the same issue. My project has no generated classes and no package-info.java; only .java files in src/main/java.
tl;dr
Update to maven-compiler-plugin 3.1 or use maven-compiler-plugin 3.0 and do not set true in maven-resources-plugin.
Long version
With zero src tree changes, Maven was always showing output like:
$ mvn -o compile [INFO]--- maven-compiler-plugin:3.0:compile (default-compile)@my-project ---[INFO]Changes detected - recompiling the module![INFO]Compiling134 source files to /home/me/my/project/target/classes
I thought it was the configuration of the maven-resources-plugin in a parent POM my project is using.
Removing this plugin from the parent POM, or redefining in my project with false fixed the incremental build problem.
I wondered why I had to do two builds after setting false for Maven to do incremental builds again, so investigated further. That is simply because the first compile generates a file (called inputFiles.lst) that is used to determine the files that have changed, so on the next compile it can use that file to detect changes. This is confirmed by a comment on MCOMPILER-187.
I realised I was using maven-compiler-plugin 3.0 and could just upgrade to
org.apache.maven.pluginsmaven-compiler-plugin3.1
which also fixed the problem. 3.1 uses maven-shared-incremental 1.1 (instead of 1.0 which maven-compiler-plugin 3.0 uses. Note that MCOMPILER-187 and MSHARED-264 are the 2 bugs covering the change.
So back with maven-compiler-plugin 3.0, I observed that the target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst was not being generated with true set. So this could be a reason why a project fails to have incremental builds when using maven-compiler-plugin 3.0.
Clearly, overwriting the resources every compile is not usually desired, but the main problem here is that inputFiles.lst is never generated, so Maven will never be able to make an incremental build. So check for the existence of inputFiles.lst as maybe another plugin has somehow caused it to not be generated.
回答3:
I don't understand why, but the solution from tucuxi's answer doesn't work in my case. In my project there are thousands of files generated by special tool and its recompilation may waste really a lot of time.
I've tried the following plugin configuration (with java level 1.5):
maven-compiler-plugin3.11.51.5true
On a second run, there are no stale files was detected but the plugin recompiled all the project again. It seems that incremental compilation actually disabled by default, and still not working even if useIncrementalCompilation=true specified.
After some googling, I've simply changed useIncrementalCompilation parameter value from "true" to "yes" and this do the trick for me.