Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I find the path of the current gradle script?

Tags:

file

gradle

We use some Gradle base scripts on an central point. This scripts are included with "apply from:" from a large count of scripts. This base scripts need access to files relative to the script. How can I find the location of the base scripts?

Sample for one build.gradle:

apply from: "../../gradlebase/base1.gradle"

Sample for base1.gradle

println getScriptLocation()
like image 927
Horcrux7 Avatar asked Jul 02 '14 10:07

Horcrux7


People also ask

How do I find my Gradle path?

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

Where are Gradle scripts?

Located in the project/module directory of the project this Gradle script is where all the dependencies are defined and where the SDK versions are declared.

What is .Gradle directory?

The Gradle user home directory ( $USER_HOME/.gradle by default) is used to store global configuration properties and initialization scripts as well as caches and log files.


2 Answers

I'm still not sure if I understood the question well but You can find path of current gradle script using following piece of code:

println project.buildscript.sourceFile

It gives the full path of the script that is currently running. Is that what You're looking for?

like image 165
Opal Avatar answered Oct 14 '22 14:10

Opal


I'm not sure if this is considered an internal interface, but DefaultScriptHandler has a getSourceFile() method, and the current instance is accessible via the buildscript property, so you can just use buildscript.sourceFile. It's a File instance pointing at the current script

like image 45
Michael Mrozek Avatar answered Oct 14 '22 13:10

Michael Mrozek