How to correctly set up IntelliJ with WSL2

Viewed 9994

I am not able to run project created under WSL2. I am getting this error. Does anyone have idea what could cause it?

Abnormal build process termination: 
C:\WINDOWS\system32\wsl.exe --distribution Ubuntu-20.04 --exec /bin/sh -c "cd /home/jakub/.cache/JetBrains/IntelliJIdea2021.1/compile-server && /usr/lib/jvm/java-11-openjdk-amd64/bin/java -Xmx700m -Djava.awt.headless=true -Djdt.compiler.useSingleThread=true -Dpreload.project.path=/home/jakub/test -Dpreload.config.path=/mnt/c/Users/Z004506P/AppData/Roaming/JetBrains/IntelliJIdea2021.1/options -Dcompile.parallel=false -Drebuild.on.dependency.change=true -Dio.netty.initialSeedUniquifier=-636684381209623859 -Djps.in.wsl=true -Dfile.encoding=windows-1252 -Duser.language=en -Duser.country=US -Didea.paths.selector=IntelliJIdea2021.1 '-Didea.home.path=/mnt/c/Program Files/JetBrains/IntelliJ IDEA 2021.1' -Didea.config.path=/mnt/c/Users/Z004506P/AppData/Roaming/JetBrains/IntelliJIdea2021.1 -Didea.plugins.path=/mnt/c/Users/Z004506P/AppData/Roaming/JetBrains/IntelliJIdea2021.1/plugins -Djps.log.dir=/mnt/c/Users/Z004506P/AppData/Local/JetBrains/IntelliJIdea2021.1/log/build-log '-Djps.fallback.jdk.home=/mnt/c/Program Files/JetBrains/IntelliJ IDEA 2021.1/jbr' -Djps.fallback.jdk.version=11.0.10 -Dio.netty.noUnsafe=true '-Djava.io.tmpdir=//wsl$/Ubuntu-20.04/home/jakub/.cache/JetBrains/IntelliJIdea2021.1/compile-server/test_77f155f7/_temp_' -Djps.backward.ref.index.builder=true -Dtmh.instrument.annotations=true -Dkotlin.incremental.compilation=true -Dkotlin.incremental.compilation.js=true -Dkotlin.daemon.enabled '-Dkotlin.daemon.client.alive.path=\"C:\Users\Z004506P\AppData\Local\Temp\kotlin-idea-13948257364742160812-is-running\"' -classpath /home/jakub/.cache/JetBrains/IntelliJIdea2021.1/compile-server/jps-IU-211.6693.111/jps-launcher.jar org.jetbrains.jps.cmdline.Launcher '/home/jakub/.cache/JetBrains/IntelliJIdea2021.1/compile-server/jps-IU-211.6693.111/netty-buffer.jar:/home/jakub/.cache/JetBrains/IntelliJIdea2021.1/compile-server/jps-IU-211.6693.111/nanoxml-2.2.3.jar:/home/jakub/.cache/JetBrains/IntelliJIdea2021.1/compile-server/jps-IU-211.6693.111/maven-resolver-transport-file-1.3.3.jar:/home/jakub/.cache/JetBrains/IntelliJIdea2021.1/compile-server/jps-IU-211.6693.111/jna-platform.jar:/home/jakub/.cache/JetBrains/IntelliJIdea2021.1/compile-server/jps-IU-211.6693.111/oro-2.0.8.jar:/home/jakub/.cache/JetBrains/IntelliJIdea2021.1/compile-server/jps-IU-211.6693.111/slf4j.jar:/home/jakub/.cache/JetBrains/IntelliJIdea2021.1/compile-server/jps-IU-211.6693.111/log4j.jar:/home/jakub/.cache/JetBrains/IntelliJIdea2021.1/compile-server/jps-IU-211.6693.111/lz4-java-1.7.1.jar:/home/jakub/.cache/JetBrains/IntelliJIdea2021.1/compile-server/jps-IU-211.6693.111/jna.jar:/home/jakub/.cache/JetBrains/IntelliJIdea2021.1/compile-server/jps-IU-211.6693.111/maven-resolver-provider.jar:/home/jakub/.cache/JetBrains/IntelliJIdea2021.1/compile-server/jps-IU-211.6693.111/annotations.jar:/home/jakub/.cache/JetBrains/IntelliJIdea2021.1/compile-server/jps-IU-211.6693.111/resources_en.jar:/home/jakub/.cache/JetBrains/IntelliJIdea2021.1/compile-server/jps-IU-211.6693.111/commons-lang3-3.10.jar:/home/jakub/.cache/JetBrains/IntelliJIdea2021.1/compile-server/jps-IU-211.6693.111/util.jar:/home/jakub/.cache/JetBrains/IntelliJIdea2021.1/compile-server/jps-IU-211.6693.111/maven-resolver-connector-basic-1.3.3.jar:/home/jakub/.cache/JetBrains/IntelliJIdea2021.1/compile-server/jps-IU-211.6693.111/jps-builders-6.jar:/home/jakub/.cache/JetBrains/IntelliJIdea2021.1/compile-server/jps-IU-211.6693.111/asm-all-9.1.jar:/home/jakub/.cache/JetBrains/IntelliJIdea2021.1/compile-server/jps-IU-211.6693.111/forms_rt.jar:/home/jakub/.cache/JetBrains/IntelliJIdea2021.1/compile-server/jps-IU-211.6693.111/guava.jar:/home/jakub/.cache/JetBrains/IntelliJIdea2021.1/compile-server/jps-IU-211.6693.111/jps-builders.jar:/home/jakub/.cache/JetBrains/IntelliJIdea2021.1/compile-server/jps-IU-211.6693.111/zip-signer.jar:/home/jakub/.cache/JetBrains/IntelliJIdea2021.1/compile-server/jps-IU-211.6693.111/jdom.jar:/home/jakub/.cache/JetBrains/IntelliJIdea2021.1/compile-server/jps-IU-211.6693.111/intellij-deps-fastutil-8.5.2-6.jar:/home/jakub/.cache/JetBrains/IntelliJIdea2021.1/compile-server/jps-IU-211.6693.111/plexus-utils-3.3.0.jar:/home/jakub/.cache/JetBrains/IntelliJIdea2021.1/compile-server/jps-IU-211.6693.111/javac2.jar:/home/jakub/.cache/JetBrains/IntelliJIdea2021.1/compile-server/jps-IU-211.6693.111/qdox-2.0.0.jar:/home/jakub/.cache/JetBrains/IntelliJIdea2021.1/compile-server/jps-IU-211.6693.111/commons-logging-1.2.jar:/home/jakub/.cache/JetBrains/IntelliJIdea2021.1/compile-server/jps-IU-211.6693.111/trove4j.jar:/home/jakub/.cache/JetBrains/IntelliJIdea2021.1/compile-server/jps-IU-211.6693.111/forms-1.1-preview.jar:/home/jakub/.cache/JetBrains/IntelliJIdea2021.1/compile-server/jps-IU-211.6693.111/jps-javac-extension-1.jar:/home/jakub/.cache/JetBrains/IntelliJIdea2021.1/compile-server/jps-IU-211.6693.111/aether-dependency-resolver.jar:/home/jakub/.cache/JetBrains/IntelliJIdea2021.1/compile-server/jps-IU-211.6693.111/http-client.jar:/home/jakub/.cache/JetBrains/IntelliJIdea2021.1/compile-server/jps-IU-211.6693.111/maven-resolver-transport-http-1.3.3.jar:/home/jakub/.cache/JetBrains/IntelliJIdea2021.1/compile-server/jps-IU-211.6693.111/idea_rt.jar:/home/jakub/.cache/JetBrains/IntelliJIdea2021.1/compile-server/jps-IU-211.6693.111/netty-codec-http.jar:/home/jakub/.cache/JetBrains/IntelliJIdea2021.1/compile-server/jps-IU-211.6693.111/jps-model.jar:/home/jakub/.cache/JetBrains/IntelliJIdea2021.1/compile-server/jps-IU-211.6693.111/gson-2.8.6.jar:/home/jakub/.cache/JetBrains/IntelliJIdea2021.1/compile-server/jps-IU-211.6693.111/kotlin-stdlib-jdk8.jar:/home/jakub/.cache/JetBrains/IntelliJIdea2021.1/compile-server/jps-IU-211.6693.111/platform-api.jar:/home/jakub/.cache/JetBrains/IntelliJIdea2021.1/compile-server/jps-IU-211.6693.111/jasper-v2-rt.jar:/home/jakub/.cache/JetBrains/IntelliJIdea2021.1/compile-server/jps-IU-211.6693.111/ant-jps.jar:/home/jakub/.cache/JetBrains/IntelliJIdea2021.1/compile-server/jps-IU-211.6693.111/java-guiForms-jps.jar:/home/jakub/.cache/JetBrains/IntelliJIdea2021.1/compile-server/jps-IU-211.6693.111/eclipse-jps.jar:/home/jakub/.cache/JetBrains/IntelliJIdea2021.1/compile-server/jps-IU-211.6693.111/eclipse-common.jar:/home/jakub/.cache/JetBrains/IntelliJIdea2021.1/compile-server/jps-IU-211.6693.111/java-langInjection-jps.jar:/home/jakub/.cache/JetBrains/IntelliJIdea2021.1/compile-server/jps-IU-211.6693.111/groovy-jps.jar:/home/jakub/.cache/JetBrains/IntelliJIdea2021.1/compile-server/jps-IU-211.6693.111/groovy-constants-rt.jar:/home/jakub/.cache/JetBrains/IntelliJIdea2021.1/compile-server/jps-IU-211.6693.111/maven-jps.jar:/home/jakub/.cache/JetBrains/IntelliJIdea2021.1/compile-server/jps-IU-211.6693.111/aspectj-jps.jar:/home/jakub/.cache/JetBrains/IntelliJIdea2021.1/compile-server/jps-IU-211.6693.111/gradle-jps.jar:/home/jakub/.cache/JetBrains/IntelliJIdea2021.1/compile-server/jps-IU-211.6693.111/devkit-jps.jar:/home/jakub/.cache/JetBrains/IntelliJIdea2021.1/compile-server/jps-IU-211.6693.111/javaFX-jps.jar:/home/jakub/.cache/JetBrains/IntelliJIdea2021.1/compile-server/jps-IU-211.6693.111/javaFX-common.jar:/home/jakub/.cache/JetBrains/IntelliJIdea2021.1/compile-server/jps-IU-211.6693.111/javaee-jps.jar:/home/jakub/.cache/JetBrains/IntelliJIdea2021.1/compile-server/jps-IU-211.6693.111/kotlin-jps-plugin.jar:/home/jakub/.cache/JetBrains/IntelliJIdea2021.1/compile-server/jps-IU-211.6693.111/kotlin-stdlib.jar:/home/jakub/.cache/JetBrains/IntelliJIdea2021.1/compile-server/jps-IU-211.6693.111/kotlin-stdlib-jdk7.jar:/home/jakub/.cache/JetBrains/IntelliJIdea2021.1/compile-server/jps-IU-211.6693.111/kotlin-stdlib-jdk8.jar:/home/jakub/.cache/JetBrains/IntelliJIdea2021.1/compile-server/jps-IU-211.6693.111/kotlin-reflect.jar:/home/jakub/.cache/JetBrains/IntelliJIdea2021.1/compile-server/jps-IU-211.6693.111/kotlin-plugin.jar:/home/jakub/.cache/JetBrains/IntelliJIdea2021.1/compile-server/jps-IU-211.6693.111/kotlin-jps-common.jar:/home/jakub/.cache/JetBrains/IntelliJIdea2021.1/compile-server/jps-IU-211.6693.111/kotlin-common.jar:/home/jakub/.cache/JetBrains/IntelliJIdea2021.1/compile-server/jps-IU-211.6693.111/javaee-jpa-jps.jar:/home/jakub/.cache/JetBrains/IntelliJIdea2021.1/compile-server/jps-IU-211.6693.111/javaee-appServers-websphere-jps.jar:/home/jakub/.cache/JetBrains/IntelliJIdea2021.1/compile-server/jps-IU-211.6693.111/javaee-appServers-weblogic-jps.jar:/home/jakub/.cache/JetBrains/IntelliJIdea2021.1/compile-server/jps-IU-211.6693.111/groovy-grails-jps.jar:/home/jakub/.cache/JetBrains/IntelliJIdea2021.1/compile-server/jps-IU-211.6693.111/groovy-grails-compilerPatch.jar' org.jetbrains.jps.cmdline.BuildMain 192.168.203.193 57615 867865da-6270-418c-bb35-8dcdf1591467 /home/jakub/.cache/JetBrains/IntelliJIdea2021.1/compile-server"
Build process started. Classpath: /home/jakub/.cache/JetBrains/IntelliJIdea2021.1/compile-server/jps-IU-211.6693.111/jps-launcher.jar
Error connecting to 192.168.203.193:57615; reason: connection timed out: /192.168.203.193:57615
io.netty.channel.ConnectTimeoutException: connection timed out: /192.168.203.193:57615
    at io.netty.channel.nio.AbstractNioChannel$AbstractNioUnsafe$1.run(AbstractNioChannel.java:261)
    at io.netty.util.concurrent.PromiseTask.runTask(PromiseTask.java:98)
    at io.netty.util.concurrent.ScheduledFutureTask.run(ScheduledFutureTask.java:170)
    at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:164)
    at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:472)   at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:500)
    at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:989)
    at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
    at java.base/java.lang.Thread.run(Thread.java:834)
Exiting.
2 Answers

Official instructions: wrong or out of date?

The official instructions from JetBrains at https://www.jetbrains.com/help/idea/how-to-use-wsl-development-environment-in-product.html#debugging_system_settings for configuring the Windows Firewall has two parts

(Official) Step 1: allow traffic from WSL (this is right)

The first step in the above link is to add a new inbound rule to allow all traffic from WSL (via PowerShell as Administrator):

New-NetFirewallRule -DisplayName "WSL" -Direction Inbound  -InterfaceAlias "vEthernet (WSL)"  -Action Allow

This command works and adds the new rule.

(Official) Step 2: Remove blocking inbound traffic to IDEA (this is wrong)

The next step in the instructions is to remove the existing rule(s) that block traffic to IntelliJ IDEA:

Get-NetFirewallRule | where DisplayName -ILike "idea*.exe" | Remove-NetFirewallRule

This command doesn't do anything because the filter part where DisplayName -ILike "idea*.exe" does not match anything.

The DisplayName property presumably corresponds to the Name column in the Firewall control panel:

IntelliJ IDEA rules already in Windows Firewall

So you can see that "idea*.exe" won't match there.

If I change the search to:

Get-NetFirewallRule | where DisplayName -ILike "IntelliJ IDEA*"

Then I do get all four rules returned in the shell output:

PS C:\Windows\system32> Get-NetFirewallRule | where DisplayName -ILike "IntelliJ IDEA*"


Name                  : TCP Query User{6288ADD6-1B2E-4BFF-9317-AEEA34194E04}C:\program files\jetbrains\intellij idea
                        community edition 2021.2\bin\idea64.exe
DisplayName           : IntelliJ IDEA Community Edition 2021.2
Description           : IntelliJ IDEA Community Edition 2021.2
DisplayGroup          :
Group                 :
Enabled               : True
Profile               : Private
Platform              : {}
Direction             : Inbound
Action                : Allow
EdgeTraversalPolicy   : DeferToUser
LooseSourceMapping    : False
LocalOnlyMapping      : False
Owner                 :
PrimaryStatus         : OK
Status                : The rule was parsed successfully from the store. (65536)
EnforcementStatus     : NotApplicable
PolicyStoreSource     : PersistentStore
PolicyStoreSourceType : Local

Name                  : UDP Query User{1AE9E9C6-02EF-4C65-8781-B1050740E936}C:\program files\jetbrains\intellij idea
                        community edition 2021.2\bin\idea64.exe
DisplayName           : IntelliJ IDEA Community Edition 2021.2
Description           : IntelliJ IDEA Community Edition 2021.2
DisplayGroup          :
Group                 :
Enabled               : True
Profile               : Private
Platform              : {}
Direction             : Inbound
Action                : Allow
EdgeTraversalPolicy   : DeferToUser
LooseSourceMapping    : False
LocalOnlyMapping      : False
Owner                 :
PrimaryStatus         : OK
Status                : The rule was parsed successfully from the store. (65536)
EnforcementStatus     : NotApplicable
PolicyStoreSource     : PersistentStore
PolicyStoreSourceType : Local

Name                  : {386E3B53-5E4D-4939-8114-74499BDA8515}
DisplayName           : IntelliJ IDEA Community Edition 2021.2
Description           : IntelliJ IDEA Community Edition 2021.2
DisplayGroup          :
Group                 :
Enabled               : True
Profile               : Public
Platform              : {}
Direction             : Inbound
Action                : Block
EdgeTraversalPolicy   : Block
LooseSourceMapping    : False
LocalOnlyMapping      : False
Owner                 :
PrimaryStatus         : OK
Status                : The rule was parsed successfully from the store. (65536)
EnforcementStatus     : NotApplicable
PolicyStoreSource     : PersistentStore
PolicyStoreSourceType : Local

Name                  : {63ED0AB1-12B9-47F2-9810-D1D446EBF9D8}
DisplayName           : IntelliJ IDEA Community Edition 2021.2
Description           : IntelliJ IDEA Community Edition 2021.2
DisplayGroup          :
Group                 :
Enabled               : True
Profile               : Public
Platform              : {}
Direction             : Inbound
Action                : Block
EdgeTraversalPolicy   : Block
LooseSourceMapping    : False
LocalOnlyMapping      : False
Owner                 :
PrimaryStatus         : OK
Status                : The rule was parsed successfully from the store. (65536)
EnforcementStatus     : NotApplicable
PolicyStoreSource     : PersistentStore
PolicyStoreSourceType : Local

Step 2: Remove blocking inbound traffic to IDEA (right)

When I disable those two Public inbound rules, and have the new added WSL inbound rule in place, then IDEA can run Java correctly where it was failing with the connection error before.

You can achieve the same disabling/removal of these two inbound Public rules for IDEA by one of the following methods:

Option 1: Windows Defender Firewall with Advanced Security > Inbound Rules

In the view as shown in the image above, right click the rules and select "Disable Rule" for each inbound rule on the Public profile.

Option 2: Disable via PowerShell

You can disable the same two rules via PowerShell (as Administrator) with the following command:

Get-NetFirewallProfile -Name Public | Get-NetFirewallRule | where DisplayName -ILike "IntelliJ IDEA*" | Disable-NetFirewallRule

Option 3: Remove via PowerShell

You can remove the same two rules via PowerShell (as Administrator) with the following command:

Get-NetFirewallProfile -Name Public | Get-NetFirewallRule | where DisplayName -ILike "IntelliJ IDEA*" | Remove-NetFirewallRule

All three of these methods worked for me and allow me to have all Windows Firewall profiles (Domain, Private, Public) enabled, and Java now runs correctly in IDEA on WSL2 projects located in the WSL2 filesystem.

Update: I had to roll back from the latest 2021.2 version to 2021.1.3, because the latest version will "lose" it's ability to connect to the WSL2 filesystem until WSL is restarted.

I have both versions installed, but I had to edit the firewall rules to allow traffic to the 2021.1.3 program (curiously also named 2021.2 in the firewall!) and add the Public profile (was just Private) to the Allow rule.

Had the same issue. All the mentioned PowerShell commands, including the ones on the JetBrains site, didn't really help.

But what eventually did the trick was that Windows Defender's "Inbound Rules" panel. Had to just find all the Restrictive rules (i.e. the ones with "Action: Block") for both "idea64.exe" and "IntelliJ IDEA" and disable them.

Works like a charm.

Related