maven

How can I force all compile dependencies to be declared in the Maven POM?


Sometimes our developers use classes that are not directly defined as compile dependencies in the POM. They rather depend on an artifact (again scope compile) which in turn has a transitive compile dependency to the artifact that contains the used class.

Like this:

Is there any way I can check this during the Maven build (except for dependency reports etc.) or even force that all compile dependencies must be declared directly in the project's POM?


Solution

  • If you want to enforce, during the build, that dependencies are correctly declared, just use the dependency:analyze-only mojo.

    You can see a good example here: http://www.stuartgunter.org/minimally-complete-dependency-declaration-maven/