Gradle build path in Eclipse

I have a Gradle build that I want to be able to run in command line and Eclipse. In the build I have a line like this:

String versionNum = new File(‘version’).text

which reads the version of the software that is used for build. This works for when I run it in command line, but when I run from under Eclipse it can’t find the file. I printed the default path from gradle script under eclipse and it is the path where my eclipse is installed, not where the gradle script is located.

How do I go about that - either changing the default path for build in Eclipse or using the location of the gradle script inside of gradle somehow.

You want to use the file() convenience method:

String versionNum = file('version').text

This will always be resolved relative to the project directory rather than the working directory.

Thanks, that worked!