15

Is there a way to configure Windows Maven and WSL Maven to use the same .m2/repository and settings.xml?

In my .bashrc from WSL I added the M2_HOME to use the same installation that Windows 10 use:

.bashrc:

export M2_HOME=/mnt/c/development/maven

Windows PATH:

C:\development\maven

But when I execute mvn clean install on Windows Bash, a .m2 folder is created in ~/.m2 (WSL folder system).

vitorvr
  • 555
  • 3
  • 16

2 Answers2

21

Found a possible solution.

I created a symbolic link from ~/.m2 to /mnt/c/Users/<username/.m2

Command: $ ln -s /mnt/c/Users/<username>/.m2 ~/.m2

Until the moment is working fine.

Felipe Mosso
  • 3,805
  • 11
  • 36
  • 61
vitorvr
  • 555
  • 3
  • 16
  • 1
    This 'works', but the performance is dreadful reading the windows filesystem from the WSL. I get build times of: * 3s if I build from the command prompt, using a .m2 cache in the windows Filesystem * 3s if I build from WSL with the .m2 cache in the WSL file system * 20s if I build from WSL with the above symlink – agentgonzo Feb 05 '21 at 18:19
1

Just an amendment to @Vitor 's response: When you created the symbolic link once, the next time (e.g. if you specified a wrong directory and want to retry) you cannot create it and you will get failed to create a symbolic link: file exists error.

As a workaround when you want to recreate the symbolic link, you can use $ ln -f -s /mnt/c/Users/<username>/.m2 ~/.m2

[OPTION] 
-f, --force
          remove existing destination files
Balu
  • 343
  • 3
  • 10