我如何找到当前gradle脚本的路径? [英] How can I find the path of the current gradle script?

查看:1817
本文介绍了我如何找到当前gradle脚本的路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们在中心点上使用了一些Gradle基本脚本。这些脚本包含在大量脚本中的应用于:中。这个基本脚本需要访问相对于脚本的文件。如何找到基本脚本的位置?



一个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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆