A repository is a storage location, where maven stores all the build artifacts and dependencies.
There are three types of repositories.
a. Local repository
b. Remote repository
c. Maven central repositories
Whenever maven wants a dependency, it searches in the local repository first, if the dependency is not present in the local repository, it downloads the dependency from maven central or configured remote repositories and place it in local repository.
While building the artifact, maven scans all the project dependencies, if a dependency artifact is not presented in the local repository (.m2), maven download the artifacts from the maven central repository and from other configured remote repositories, copy the artifact to the local repository.
Location of Local Repository
maven local repository is presented at %USER_HOME%/.m2. For example, in my case, it is located at ‘C:\Users\krishna\.m2’What is the maven public or central repository?
https://repo1.maven.org/maven2/ : This repository is hosted by the maven community and available for public usage.
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <repositories> <repository> <id>my-repo1</id> <name>your custom repo</name> <url>http://jarsm2.dyndns.dk</url> </repository> <repository> <id>my-repo2</id> <name>your custom repo</name> <url>http://jarsm2.dyndns.dk</url> </repository> </repositories> </project>
Where is my copied dependency location in local repository?
Let me explain this with an example.
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.9.0</version>
</dependency>
‘groupId’, ‘artifactId’ and ‘version’ together used to uniquely identify the artifact. By default, all the artefacts are downloaded to {USER_HOME}/.m2/repository folder. groupId, artifacteId and version are transformed to directories in the local file system.
For example, the groupId ‘com.google.code.gson’ is changed to ‘com/google/code/gson’.
$ls ~/.m2/repository/com/google/code/gson/gson/2.9.0
_remote.repositories gson-2.9.0.jar.sha1
gson-2.9.0-sources.jar gson-2.9.0.pom
gson-2.9.0-sources.jar.sha1 gson-2.9.0.pom.sha1
gson-2.9.0.jar m2e-lastUpdated.properties
No comments:
Post a Comment