We have a Maven project (packaged as JAR) with Java files. A new Java source file was recently added to this project. The path in which the Java file was added, does not match its package declaration. As expected, Eclipse shows an error in the class for the mismatch. However, Maven builds the project just fine. In the generated JAR file, the .class file is present in the path indicated by the package declaration. We tried moving the Java source file to other incorrect folders (i.e. different from the package declaration), but every time Maven builds the project fine.
So, does Maven ignore the actual directory in which the .java file is present? Does it only consider package declaration?
The Maven Compiler plugin internally assembles a command line call containing the arguments passed to javac, one argument per source file (using the sourcefiles
version of the javac call). It does pass the actual source folders also for meta-capabilities like annotation processing, but when individual source files are passed to javac, these take precedence and the compiler has no efficient way to find out which file belongs to which source folder and hence can't validate the package structure.
The Maven Compiler Plugin internally uses the Plexus Compiler API, and you can find the relevant code in these two classes:
AbstractCompiler
JavacCompiler
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With