Maven - Interview Questions and Answers on Dependencies

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

Ans. run mvn -X

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

Ans. Using  

mvn dependency:tree

Q3.  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. 

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

Q4.  What are the benefits of transitive dependency in Maven ?

Ans. Transitive dependencies allows to avoid specifying the libraries that are required by the project which are specified in other dependent projects - Remote or Local.

Q5.  What is a cyclic dependency ?

Ans. A has dependency of B, B has dependency of C and C has dependency of A,architecture,technical lead

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

Q8.  Which of the following is dependency exclusion ?

 a. A doesn't depend on C and then A marks C as excluded.
 b. A Depends on B and B depends on C and then A can mark B as excluded.
 c. A and B depends on C and then they can mark C as excluded.
 d. A depends upon B and B depends upon C then A marks C as excluded.

Ans. A depends upon B and B depends upon C then A marks C as excluded.