Intellij and the WSL: Setting Environment Variables
已回答
I am loading a WSL Gradle project.
The Gradle build makes use of a few environment properties.
How do I set these environment properties?
I have Conda on the WSL machine (if that helps).
I presume Intellij is running some wsl command.
What is that wsl command?
请先登录再写评论。
Refs:
* https://intellij-support.jetbrains.com/hc/en-us/community/posts/360003302920-Using-WSL-with-gradle-build
>The Gradle build makes use of a few environment properties.
>How do I set these environment properties?
Please use standard Gradle means, please see Build Environment in Gradle documentation.
I am not sure what you mean by standard Gradle means (as environment variables are one such means).
Do you mean using gradle.properties? or one of the other "standard Gradle means".
I'm sorry for being sparse. By default in a Gradle project, the IDE uses Gradle itself to build and run the applications. So to configure the Gradle build and pass environment variables to is one should just use the same means that the Gradle provides just like you would build from the command line. Although indeed there coudl be an issue with GRADLE_OPTS environment variable in the IDE: IDEA-253331 GRADLE_OPTS not picked up by builds triggered via IDE
What are you trying to achieve and what have you tried already? Thanks.
I set environment variables in the default user's `.bashrc` file.
The `.bashrc` does not seem to be run.
The environment parameters set there do not seem to be accessible in the gradle script.
I could use system-internals processExplorer to see how the gradle process is spawned but I thought I would ask here first.
What result do you get if run the Gradle task from the command line?
Also check from the command line terminal that the environment variables are available.
I do not have access to the Windows machine today; I will check tomorrow.
Am I to understand that Gradle is run from a terminal started in the same way as the IDEA terminal?
I presume the Gradle process is not a sub-process of the IDEA terminal, but is started in the same way?
>Am I to understand that Gradle is run from a terminal started in the same way as the IDEA terminal?
IDE invokes actual Gradle tasks when you build from IDE. And it should take the same environment as in terminal, yes.
>I presume the Gradle process is not a sub-process of the IDEA terminal, but is started in the same way?
The environment in the terminal looks correct, i.e. the environment variables (including conda settings) look correct.
However, when I try to switch branches I get the message:
```
Couldn't checkout origin/foo
setsid: invalid option -- 'w'
Usage: setsid [options] <program> [arguments ...]
Options:
-c, --ctty set the controlling terminal to the current one
-h, --help display this help and exit
-V, --version output version information and exit
For more details see setsid(1).
```
When I perform the checkout from the IDEA/Terminal it works without error.
Might this be a related issue?
I am thinking that my problems are due to using CentOS 7 as the WSL instance.
e.g. the `setsid` command does not support the `-w` option in CentOS 7.
Is there a document describing the OS's supporting IDEA/WSL?
Or, back to my original request...
Is there a way to get a trace of the commands executed by IDEA/WSL?
One could enable debug logs by adding
#com.intellij.execution.wsl
line into Help | Diagnostic Tools | Debug Log Settings... dialog. IDE will log commands it executes on WSL.I do not think Git issue is related to WSL environment. I also still do not understand the exact problem you are having with WSL. Have you been able to check this with the Gradle from the command line?
I stumbled on this same issue. git works through the terminal but not through IntelliJ. WSL is CentOS7
Temporarily, you can set your IntelliJ to use the windows git.exe and make git.exe trust any directory. This will enable the IDE to execute its git commands in the WSL projects' folder