Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to setup gradle with Intellij IDEA with WSL2 project?

I have a project cloned inside ubuntu wsl \\wsl$\Ubuntu\home\username\project. Opened it inside Intellij IDEA Ultimate 2020.1.3 and tried to import as gradle project, but I am getting uninformative error message: enter image description here

Here's my gradle config in IDEA: enter image description here

The question is how should I open my project in IDEA then?

EDIT:

Logs from imported project contain this stack trace. Possibly this causes the issue.

org.gradle.tooling.GradleConnectionException: Could not install Gradle distribution from 'https://services.gradle.org/distributions/gradle-6.5.1-all.zip'.
    at org.gradle.tooling.internal.consumer.DistributionFactory$ZippedDistribution.getToolingImplementationClasspath(DistributionFactory.java:139)
    at org.jetbrains.plugins.gradle.GradleConnectorService$DistributionWrapper.getToolingImplementationClasspath(GradleConnectorService.kt:287)
    at org.gradle.tooling.internal.consumer.loader.CachingToolingImplementationLoader.create(CachingToolingImplementationLoader.java:41)
    at org.gradle.tooling.internal.consumer.loader.SynchronizedToolingImplementationLoader.create(SynchronizedToolingImplementationLoader.java:44)
    at org.gradle.tooling.internal.consumer.connection.LazyConsumerActionExecutor.onStartAction(LazyConsumerActionExecutor.java:147)
    at org.gradle.tooling.internal.consumer.connection.LazyConsumerActionExecutor.run(LazyConsumerActionExecutor.java:129)
    at org.gradle.tooling.internal.consumer.connection.CancellableConsumerActionExecutor.run(CancellableConsumerActionExecutor.java:45)
    at org.gradle.tooling.internal.consumer.connection.ProgressLoggingConsumerActionExecutor.run(ProgressLoggingConsumerActionExecutor.java:61)
    at org.gradle.tooling.internal.consumer.connection.RethrowingErrorsConsumerActionExecutor.run(RethrowingErrorsConsumerActionExecutor.java:38)
    at org.gradle.tooling.internal.consumer.async.DefaultAsyncConsumerActionExecutor.lambda$run$0(DefaultAsyncConsumerActionExecutor.java:62)
    at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:64)
    at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:48)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
    at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:56)
    at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: java.io.IOException: Incorrect function
    at java.base/sun.nio.ch.FileDispatcherImpl.lock0(Native Method)
    at java.base/sun.nio.ch.FileDispatcherImpl.lock(FileDispatcherImpl.java:100)
    at java.base/sun.nio.ch.FileChannelImpl.tryLock(FileChannelImpl.java:1161)
    at java.base/java.nio.channels.FileChannel.tryLock(FileChannel.java:1165)
    at org.gradle.wrapper.ExclusiveFileAccessManager.access(ExclusiveFileAccessManager.java:55)
    at org.gradle.wrapper.Install.createDist(Install.java:48)
    at org.gradle.tooling.internal.consumer.DistributionInstaller.install(DistributionInstaller.java:72)
    at org.gradle.tooling.internal.consumer.DistributionFactory$ZippedDistribution.getToolingImplementationClasspath(DistributionFactory.java:133)
    ... 15 more

EDIT2: Attaching full logs of instantiating new project with gradle init command: https://pastebin.com/G4xhR3N3

like image 427
Praytic Avatar asked Jul 16 '20 13:07

Praytic


People also ask

How do I sync a project with Gradle files in IntelliJ?

There is a useful shortcut Ctrl + Shift + A , after which a window appears and you can type some command that you would like IntelliJ to run. Just type "sync" in there and it will find that command Sync Project with Gradle Files, even if it's not visible in the menu.


Video Answer


1 Answers

Workaround that was useful in my case (I have WSL 2):

  • Create a project folder in your Windows filesystem.
  • Using mklink and mklink /D, create symbolic links to your WSL files and folders (I have the WSL 2 filesystem, \wsl$, mounted as my L: drive, probably this is a requirement). The mklink command requires to be run as Administrator (run cmd.exe as Admin). Example: "mklink /D src L:\home\john\project\src". List of files that I sym-linked:
    • <SYMLINKD> .git/ (edit: git support in Windows side doesn't work with this approach, as git detects the difference between symlinks and regular files; however, you can still use git on WSL).
    • <SYMLINK> .gitignore
    • <SYMLINK> build.gradle
    • <SYMLINK> settings.gradle
    • <SYMLINKD> src/
  • Notice .gradle, gradle, gradew, gradlew.bat, and .idea don't have symbolic links. WSL should have its own .gradle and build folders, and no IntelliJ gradle wrapper.
  • IntelliJ Gradle and WSL gradle should work fine and independently this way.
like image 146
Daniel Vazquez Avatar answered Nov 15 '22 08:11

Daniel Vazquez