Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does maven compile only the modified java files?

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 modified or not? I believe it is not using the last modified property of the file.

Reason for my belief: I had a module, after merging a change from svn, i gave mvn install and it didn't compile the modified file and when i looked at the change i saw that 'long' were modified to 'Long' in getters and setters.

So i just want to know how maven identifies if a java file has changed or not?

(P.S I'm using Apache Maven 3.0.3, if that matters)

like image 719
Senthil Kumar Avatar asked Aug 02 '12 07:08

Senthil Kumar


People also ask

Does Maven compile Java?

The package goal will compile your Java code, run any tests, and finish by packaging the code up in a JAR file within the target directory. The name of the JAR file will be based on the project's <artifactId> and <version> . For example, given the minimal pom.

What is default compile in Maven?

The Compiler Plugin is used to compile the sources of your project. Since 3.0, the default compiler is javax. tools. JavaCompiler (if you are using java 1.6) and is used to compile Java sources.

What is the Maven command to compile all files including the test files?

mvn compile: Compiles source code of the project. mvn test-compile: Compiles the test source code. mvn test: Runs tests for the project. mvn package: Creates JAR or WAR file for the project to convert it into a distributable format.

Does Maven depend on Java?

Maven is a Java tool, so you must have Java installed in order to proceed. Depending upon your network setup, you may require extra configuration. Check out the Guide to Configuring Maven if necessary.


1 Answers

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.

like image 199
Duncan Jones Avatar answered Oct 13 '22 00:10

Duncan Jones