How to get WSL2 working with IntelliJ IDEA 2021.1

Viewed 944

I have no idea how to get IntelliJ IDEA 2021.1 working with WSL. I spent two days searching trough internet but I wasn't able to get it running. I am able to create new project with JDK located in WSL but when I press "play button" I receive this:

Executing pre-compile tasks...
Loading Ant configuration...
Running Ant tasks...
Cannot assign requested address: bind
Synchronizing output directories...
4/16/2021 7:57 PM - Build completed with 1 error and 0 warnings in 77 ms

What I tried was also to use maven from WSL but that also didn't help. Does anyone has idea what I am doing wrong?

1 Answers

Jetbrains added an option to work around the issue (has to do with your WLS2 /etc/resolv.conf being modified due to VPNs, etc.):

https://youtrack.jetbrains.com/issue/IDEA-265522#focus=Comments-27-4808360.0-0

From the issue link:

Thanks, the issue with generateResolvConf=false in /etc/wsl.conf is reproduced. The fix will be available in 2021.1.x builds, exact fix version will be available later (see "Available in" field).

After updating to a version with the fix, please do the following to change how Windows host IP is obtained:

Open "Help | Find Action...", locate "Registry..." there and open it.
In the opened "Registry" dialog, find wsl.obtain.windows.host.ip.alternatively registry key (disabled by default) and enable it.
Restart IDE to apply the changes.
Related