Changing the Maven repository location in Eclipse is a straightforward process. By default, Maven uses the .m2/repository
folder in the user home directory (e.g., C:\Users\YourUsername\.m2\repository
on Windows or ~/.m2/repository
on Linux/macOS).
To change the Maven repository location in Eclipse, follow the steps below:
1. Manually Updating the M2_REPO Location
1.1. Navigate to Windows > Preferences

1.2. Navigate to Java > Build path > Classpath Variables

1.3. Define new classpath variable “M2_REPO”
Create new variable M2_REPO
and point it to maven local repository location.

1.4. Verify that variable has been added

2. Update M2_REPO from Command Line
Alternatively, you can define and add M2_REPO via the Maven command “eclipse:configure-workspace“.
For example, this is the output of the command in my system.

3. Set the Repository Location Temporarily
If you do not want to modify the settings.xml
file, you can set the Maven repository location temporarily by passing the -Dmaven.repo.local
flag during a Maven command:
This change is only valid for the current Maven execution.
Happy Learning !!
Comments