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.


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:

        <name>Offline Repository</name>
        <name>Offline Repository</name>

As simple as that.