Build.gradle - Configure Eclipse so that System.getenv('PATH') returns the same value as from command line in macOS

The environment:

  • macOS 10.15.7
  • Gradle 6.8.2
  • Eclipse Version: 2020-12 (4.18.0)

The problem:

I have a very simple Gradle build script that works from the command line but fails when running within Eclipse.
I have boiled it down to the fact that System.getenv(‘PATH’) returns 2 different values depending on gradle being run from command line or from eclipse
I have created a very simple gradle build that only contains:

 tasks.register('debug') {
 doLast {
	 println System.getenv('PATH')
 }

}

If I run the task from Eclipse, the output is:

> Task :debug
/usr/bin:/bin:/usr/sbin:/sbin

If I run the tasks from the macOS command line the output is:

> Task :debug
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/share/dotnet:/opt/X11/bin:~/.dotnet/tools:/Library/Apple/usr/bin:/Library/Frameworks/Mono.framework/Versions/Current/Commands:/opt/ImageMagick/bin:/Applications/Wireshark.app/Contents/MacOS:/Applications/Xamarin Workbooks.app/Contents/SharedSupport/path-bin

It is clear that Eclipse somehow does not have access to the same PATH as my command line.

So my questions are:

  1. Can I force Eclipse to have access to the same PATH environment variable as my command line
  2. Can I configure Eclipse to add custom entries to the PATH environment variable
  3. Can I configure my Gradle run configuration in Eclipse to add custom entries to the PATH environment variable
  4. Can I configure Gradle, in general, to add custom entries to the PATH environment variable

Thanks

Buildship does not spawn a separate process when launching Gradle. An unfortunate consequence of that is that the created build invocations will all inherit PATH from Eclipse. There are low-hanging fruits here. The correct solution would be to spawn a separate process to run Gradle invocations, but even then, the required extra resource is questionable.

Can I force Eclipse to have access to the same PATH environment variable as my command line

No.

Can I configure Eclipse to add custom entries to the PATH environment variable

You do that in the .options file present in your Eclipse installation.

Can I configure my Gradle run configuration in Eclipse to add custom entries to the PATH environment variable

No.

Can I configure Gradle, in general, to add custom entries to the PATH environment variable

Not with Gradle configuration. However, you invoke Gradle, you can configure the PATH at the callsite.

I have found a workaround for this, it works on macOS (I guess that Windows did not had the original problem)

If I simply start Eclipse from a command line with:
/Applications/Eclipse.app/Contents/MacOS/eclipse

Or from finder with:
Applications->
Eclipse->
Right click->
Show Package Contents->
MacOS->
double click on Eclipse

Then I get the same environment variable in Buildship as I have from Gradle command line