Gradle miss environment variable when running tasks from IntelliJ IDA in WSL - gradle

I'm working on a Gradle project with multiple sub modules. Some of these are using maven. Thus one Gradle task is running maven from the MAVEN_HOME directory. This task is called by IntelliJ IDEA during Gradle refresh. When running IntelliJ Community Edition 2021.1 on an Ubuntu 20_05 VM, everything works fine. When running the same version of IntelliJ Windows with WSL 2, the task fails with error
MAVEN_HOME environment variable not set, unable to locate mvn executable for build
When I open a shell in WSL, I see that the MAVEN_HOME is actually set. I've defined it in my ~/.profile file. I can build my project from the terminal command line. IntelliJ IDEA uses the Gradle wrapper for building the project. It uses the shebang #!/bin/env sh. So it is not opening a login shell und thus the ~/.profile files are not read.
Any ideas how to solve this problem?

Related

IntelliJ IDE - cannot run Maven from terminal inside IDE (path is set)

last week I got new laptop from company so I had to do new installation from scratch.
I installed my JDK, Maven, git bash and IDE, configured environment variables for MAVEN_HOME and JAVA_HOME... added them to Path with for example: %JAVA_HOME%\bin and same for maven.
Both JDK and Maven work perfectly fine with cmd and git bash or even with maven plugin in IntelliJ.
But if i want to open terminal inside of IDE and run some maven command it will give me mvn not found error.
I use /wanna use git bash, but it gives same error for cmd inside of IDE as well.
I've checked terminal system environemtns setting in IDE and I can find MAVEN_HOME inside and I even tried to add M2_HOME but error is the same (I do reset terminal after every change).
Also, in git bash if I write echo $PATH it will return me my variables as it can be seen here:
/mingw64/bin:/usr/bin:/c/Users/user.name/bin:/c/Program Files (x86)/Common Files/Oracle/Java/javapath:/c/Windows/system32:/c/Windows:/c/Windows/System32/Wbem:
/c/Windows/System32/WindowsPowerShell/v1.0:/c/Windows/System32/OpenSSH:/c/Program Files/Docker/Docker/resources/bin:/c/ProgramData/DockerDesktop/version-bin:%JAVA_H
OME%/bin:%MAVEN_HOME%/bin:/cmd:/c/Users/prese/AppData/Local/Microsoft/WindowsApps:/c/Users/username/AppData/Local/Programs/Microsoft VS Code/bin:/c/Program Files/herok
u/bin
I never had an issue like this as usually all I had to do after installig java/maven and git bash was to change default terminal in IDE to git bash.... and that's it.
But something is different this time around.
Please do share what can I do and/or try.
EDIT:
If I write:
export PATH=$PATH:/c/Program\ Files/Apache\ Maven/apache-maven-3.6.3/bin
This will set maven and it will work... but only for this instance of terminal... new instace and session will not have it

Gradle WSL: unknown property from buildSrc

I have a project with a buildSrc that has a package (eg abc).
I use that package in my other project build.gradle files (eg abc.test()). Given that it's under buildSrc, it is imported automatically, and it's been working on my macbook.
I am now trying to do the same thing with windows + WSL.
My current setup involves having java and gradle installed in windows (and working via Android Studio), while also having java and gradle installed in WSL. The short story is that WSL's gradle kept complaining about bad java_home paths when they were shared, so I installed everything as if it were pure linux.
When trying to run gradle build, the command now complains:
> Could not get unknown property 'abc' for object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.
Is there a way around this? Is there a better workaround to running gradle tasks from WSL? I'm using this in a pre-commit, so I'm even open to having it run the command "through windows" if it helps. As of now, I suspect it's a pathing issue, because build commands work fine in the IDE.

IntelliJ terminal setup

I used to run gradle test via IntelliJ terminal with following command,
>gradle test Accidentally I deleted my windows path environmental variable in my windows 7 machine.
After this when I run above command I get below error
'gradle' is not recognized as an internal or external command,
operable program or batch file.
What should I add in path environmental variable to get this run again
IntelliJ version 13.0.3
I added all java and gradle path under env. variable (I can run test via cygwin with above command)
Thanks
This issue was resolved after restarting the windows. Because after adding path to the env variable and restart IntelliJ was not enough.
I should have done this before posting the question.
Please bear with me if any convenience caused.
Cheers

IntelliJ cannot find Maven M2_HOME environment variable

I'm trying to make my first step with Maven system. But I cannot understand if I should install it separately or if it comes built-in with IntelliJ 13 Community Edition? My system is Windows 7.
Maven does not come bundled with Intellij. You need to install the version of Maven you'd like to use on your computer.
Intellij has a Maven plugin, which requires that you either set M2_HOME or supply it with the location of your Maven install.
First you should it install it separately cause you will need it on command line. Furthermore it's best to understand maven on command line first and than make the integration step into Maven with an IDE of your choice.

How do I get Netbeans 7.3.1 to see my environment variables on Mac OS X (10.8.3)?

I'd like to run Netbeans from the launcher and get it to see environment variables.
Background:
I'm using netbeans for a rails project and have configured my devel database with configurations using environment variables.
Unfortunately Netbeans appears unable to read those variables even when I list them in /etc/profile (for all users).
I can explicitly run Netbeans from the terminal: /Applications/NetBeans/NetBeans\ 7.3.1.app/Contents/MacOS/netbeans and that gets things to work but I'd much rather run it from
the launcher if I can solve this problem.
You could define them in
/etc/launchd.conf
and restart system. See this for example
If you run NetBeans from the command line, e.g.
open
/Applications/NetBeans/NetBeans 8.1.app/Contents/Resources/NetBeans/bin/netbeans
then the environment variables defined in the shell initialization script will be visible in the NetBeans application. If you start NetBeans via the icon, the initialization scripts are not run.

Resources