Apache Maven - Interview Questions and Answers on Repository

Q1. Where do we configure repositories in Maven ?

Ans. Within settings.xml in either MAVEN_HOME or .M2 directory.

Q2. What are different type of repositories in Maven ?

Ans. Local and Remote. 

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

Q4. What is maven repository central ?

Ans. Its the repository provided by Maven. In case your POM specify the dependencies and its not available in the configured local and the remote repository. It then looks for the resource in Maven Central. Maven provides most of the generic dependency resources at this remote location.

Q5.  What is the sequence in which Maven looks for the resources ?

 a. Remote-> Maven Central - > Local
 b. Local -> Remote - Maven Central
 c. Remote-> Local -> Maven Central
 d. Maven Central -> Local -> Remote

Ans. Local -> Remote - Maven Central

Q6.  Which of the following is not type of Maven Repository ?

 a. Local
 b. Remote
 c. Maven Central
 d. Maven Local

Ans. Maven Local

Q7.  What is the default location of local repository ?

 a. ~/.m2/repo
 b. ~/m2./home/repository
 c. ~/m2./repository
 d. ~/m2./home/repo

Ans. ~/m2./repository