我如何找到当前gradle脚本的路径? [英] How can I find the path of the current gradle script?
问题描述
一个build.gradle的示例:
apply from:../../gradlebase/base1.gradle
Base1.gradle示例
println getScriptLocation()
我不确定这是否被认为是内部接口,但 DefaultScriptHandler
有一个 getSourceFile()
方法,当前实例可以通过 buildscript
属性,因此您可以使用 buildscript.sourceFile
。它是指向当前脚本的 File
实例
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()
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
这篇关于我如何找到当前gradle脚本的路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!