eclipsegradlebuildship

Buildship how to set environment variable on project scope


We switched for our project from ant to gradle. Now the gradle script looks like this

[...]    
def filterFile = System.getProperty('filter.file')
[...]

All tasks heavily depend on the environment variable filterFile. We use eclipse (Oxygen.2 Decemeber 2017) with buildship (2.2.1 v20180125-1441) (which came somehow preinstalled with eclipse? Is that correct that buildship automaticaly comes with eclipse?)

The only way I could make it work is set the variable on task level see screenshot

enter image description here

The same DOES NOT work on project level: enter image description here

enter image description here

When I now remove the setting on the task and put it on the project global setting and execute the very same task it says:

Program Arguments: None
Build Scans Enabled: false
Offline Mode Enabled: false
Gradle Tasks: copyHtml

Filter file null not loaded, some tasks may fail

while this works when I set it on the task level.

This are my preference settings for gradle in eclipse: enter image description here

Can you please explain of how to set a project wide environment variable. BTW: I googled the problem and found out about home directory gradle.properties file. But I think this will set project variables and NOT environment variables. As we switched from ant to gradle the gradle build script depends on System.getProperty('filter.file') which might be the wrong way to set this up for gradle but it's the remainigs from the migration from ant so it would be hard for us to change this for every task (as we have plenty of them).

Please advise!


Solution

  • Please note, that those are system properties (a Java thing) instead of environment variables (an operating system thing).

    Why does your current setup not work?

    Your second example does not apply project-wide command line arguments, but command line arguments for a Eclipse Run configuration, that executes Gradle without any tasks specified. This will cause Gradle to either just run the configuration phase without the execution of any tasks, or, if you specified them in your build script, to run the default tasks.

    How can you solve your problem?

    As you can read in the Gradle documentation on system properties, you can not only use the command line option -D to register a system property, but also the gradle.properties file(s) you already mentioned. Just add the systemProp prefix to the property name:

    systemProp.filter.file=hhe-lenovo.dev.properties