The structure of my Gradle project is as follows:
Project โโโ app โโโ build.gradle โโโ foo โโโ bar.txt ยท ยท ยท โโโ build.gradle
Usually, to get the absolute path to the foo
folder, I can simply do new File('foo').getAbsolutePath()
in the root build.gradle
file.
But this, unfortunately, does not work if you run the Gradle script because of the project directory, for example, by doing something like this:
$ trunk/gradlew -b trunk/build.gradle tasks
If the previous Gradle command is looking for the foo
directory in the parent Project object, because I started the script there.
Is there a way to get the absolute project path where build.gradle is, even if you run your script from another directory? Or is there another way to get a link to a directory in the same folder as the script?
I also tried with getClass().protectionDomain.codeSource.location.path
, but it returns the path to the Gradle cache directory.
source share