Describe the Maven build lifecycle and how you would fix a dependency conflict.
Answer
- Lifecycle: validate, compile, test, package, verify, install, deploy;
clean removes target/. - Dependencies are resolved from Maven Central or a company repository (Nexus/Artifactory) into
~/.m2. - Conflict symptoms:
NoSuchMethodError, ClassNotFoundException, two versions of the same library. - Diagnose with
mvn dependency:tree (add -Dverbose). - Fix: pin the version in
dependencyManagement, add <exclusions> for the unwanted transitive version, or import a BOM. - Prevent: use
maven-enforcer-plugin (dependencyConvergence), avoid SNAPSHOTs in releases.
Practice this question in Repaso