How does maven compile only the modified java files?

后端 未结 3 497
抹茶落季
抹茶落季 2020-12-11 15:24

I was just curious to know this, when i give mvn install without doing \'clean\', maven compiles only the modified java files. How does maven identify a java file is modifie

相关标签:
3条回答
  • 2020-12-11 15:53

    I believe the Maven compiler plugin uses last modified dates on the source and class files to determine whether recompilation is necessary.

    The compiler website is rather short on information, but the compiler:compile goal page has information on the following attribute, which finely tunes the staleness calculations: http://maven.apache.org/plugins/maven-compiler-plugin/compile-mojo.html#staleMillis. That's about the only official statement regarding staleness.

    0 讨论(0)
  • 2020-12-11 16:01

    Robert Scholte's comment at https://issues.apache.org/jira/browse/MCOMPILER-205 explains the process. It depends on the "useIncrementalCompilation" option of the "maven-compiler-plugin" (and on the version of it btw, I've only managed to have "useIncrementalCompilation" work with 3.1, not 3.0):

    I see there's some confusion, so something needs to be changed, maybe improving documentation is good enough. Looking at the code, you'll see that non-incremental will only look at changed sourcefiles. Incremental will also verifies if dependencies have changed and if files have been added or removed. If it has changed, it'll remove the complete classes-directory. The reason is that the default java compiler is quite fast, likely much faster than analyzing per file what to do with it. IIUC the eclipse compiler is a real incremental compiler, so we could decide that based that based on the used compiler not to drop the classes directory.

    0 讨论(0)
  • 2020-12-11 16:18

    Without knowing much about maven, I can tell you that generally speaking, "make"-like tools use the "last changed" timestamp, which would explain the issue you had with svn ( see Wikipedia on Subversion's weaknesses.

    0 讨论(0)
提交回复
热议问题