3

I've ran into an issue with Maven a few times now where the build does not fail if there's an inconsistency between the package declaration and the path of the source file. From other Stackoverflow questions, there are several examples that shows Eclipse catches this type of error no problem and explains why Maven doesn't:

Eclipse says package declaration does not match expected package "" Eclipse: The declared package does not match the expected package Maven + Java package declaration

There are a few different issue that can arise when Maven doesn't catch this inconsistency including run-time failures to load classes or unit tests omitted from a build without flagging any errors.

Although Maven doesn't catch this with the compiler, is there any Maven plugin out there that will validate the package name to the source path? Or possibly some other configuration value that can be set in the pom.xml or settings.xml to get Maven to verify these are consistent?

Community
  • 1
  • 1
Hazok
  • 5,373
  • 4
  • 38
  • 48
  • Did you try using Eclipse compiler instead of javac one in your build? – Tome Apr 10 '15 at 00:14
  • I'm not asking for Eclipse on this one. This question specifically targets Maven. – Hazok Apr 10 '15 at 00:40
  • 1
    I meant using ECJ as compiler for the Maven build, instead of the default Javac usage, see how to use different compilers here: http://maven.apache.org/plugins/maven-compiler-plugin/non-javac-compilers.html – Tome Apr 10 '15 at 06:46
  • This is for a company build system and not on my local machine; should be Oracle JDK 1.7. – Hazok Apr 17 '15 at 21:46
  • Using ECJ doesn't mean you use another JDK, it is just that you use another compiler than _javac_. One advantage of using ECJ is that it is a dependency, so everyone is guaranteed to use the exact samr version of the compiler, whereas with _javac_ you rather rely on the JAVA_HOME env variable. – Tome Apr 18 '15 at 18:15
  • Sounds fine on the semantics. Still looking for an answer... – Hazok Apr 19 '15 at 03:32
  • If you post a sample project that illustrates and reproduces the issue, providing a ready-to-use answer will be easier. – Tome Apr 20 '15 at 10:59

0 Answers0