Apache Maven - Interview Questions and Answers on Dependencies

Q1.  How do I determine which POM contains missing transitive dependency?

Ans. run "mvn -X"

Q2. How does Maven looks for a dependency or resource ? 

Ans. It refers to the settings.xml to look for the repositories to look for the resource. First It looks into the configured local repository, then it looks into the configured Remote repositories. If the resource is still not found , it looks it within maven repository central i.e repo1.maven.org. If its still not found, it throws the exception saying "Unable to find resource in repository central".

Q3.  How can we see Dependencies for the project and where exactly they are defined ?

Ans. Using  

mvn dependency:tree

Q4.  What is a transitive dependency ? Can we override Transitive Dependency version and If Yes, how ?

Ans. Transitive dependency is the dependencies not defined directly in the current POM but the POM of the dependent projects.  Transitive dependencies allows to avoid specifying the libraries that are required by the project which are specified in other dependent projects - Remote or Local.

Yes we can override transitive dependency version by specifying the dependency in the current POM. 

Q5.  What is a cyclic dependency ?

Ans. A has dependency of B, B has dependency of C and C has dependency of A.

With Maven 2 , came transitive dependency wherein in above scenario, C will acts as a dependency of A as if this dependency has been defined directly in A but the negative side is that if it leads to cyclic dependency , it creates problems.

Q6.  How do I determine which POM contains missing transitive dependency?

 a. mvn -A
 b. mvn -M
 c. mvn -R
 d. mvn -X

Ans. mvn -X

Q7.  Which of the following is not a dependency scope in Maven ?

 a. Compile
 b. Test
 c. System
 d. Export

Ans. Export