Java - Downloading Maven Dependencies as a Local Repository for Offline Build and Usage
Java - Downloading Maven Dependencies as a Local Repository for Offline Build and Usage
I had a scenario where in a Jenkins slave machine while configuring CI/CD, it was not allowed to access the internet to download Maven dependencies due to restrictions. Hence, I had to find a way to download the remote repositories of only required files to a local repository and push it along with the codes and map pom.xml to use it.
Instructions
1. Download offline repository of only required dependencies into a file path
Run command in project root directory:
mvn dependency:go-offline -Dmaven.repo.local=./repo
2. Map pom.xml
Bottom of pom.xml:
<repositories> <repository> <id>offline</id> <name>Offline Repository</name> <url>file://${project.basedir}/repo</url> </repository> </repositories> <pluginRepositories> <pluginRepository> <id>offline</id> <name>Offline Repository</name> <url>file://${project.basedir}/repo</url> </pluginRepository> </pluginRepositories>
As simple as that.