Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle: get folder from which "gradle" was executed

Tags:

gradle

I am trying to use gradle tasks as kind of "OS agnostic shell-script". I have no problems in writing the logic of the build file, but I would like to be able to run it from any folder.

My first attempt was to put a folder with my build.gradle file on the path, and then try to execute:

gradle myMask 

from a folder that doesn't contain build.gradle - but that doesn't work.

My next attempt was:

gradle -b /folder/containing/build.gradle myTask 

But that worked only to some extend. In my task I would like to find all files in CURRENT DIRECTORY. current - meaning not the one that contains build.gradle but the one from within which I am executing "gradle ....."

I have tried:

file(".") 

and

file("$projectDir") 

and some more, but all of them point to the folder containing build script, no the one from which I am executing it.

Any ideas how can I do that?

like image 320
Michał Margiel Avatar asked May 24 '13 06:05

Michał Margiel


People also ask

Where does .Gradle folder come from?

The global properties file should be located in your home directory: On Windows: C:\Users\<you>\. gradle\gradle.

Where is .Gradle folder located?

gradle folder location for Android studio, you must: Define the GRADLE_USER_HOME environment variable to point to C:\WorkFolder\ . gradle. You can read more in the Configure the IDE docs.

How do you identify a Gradle project?

In Android Studio, go to File > Project Structure. Then select the "project" tab on the left. Your Gradle version will be displayed here. If you are using the Gradle wrapper, then your project will have a gradle/wrapper/gradle-wrapper.

Where do Gradle build files go?

gradle file is located inside your project folder under app/build. gradle.


1 Answers

and the winner is:

System.getProperty("user.dir") 
like image 148
Michał Margiel Avatar answered Nov 09 '22 22:11

Michał Margiel