如何获得Groovy的文件build.gradle的完整路径? [英] How get full path to file build.gradle by Groovy?
问题描述
我需要在buiid.gradle-file附近的java-project中创建文件.我必须在build.gradle-file中创建任务(Groovy任务),我的任务必须在项目中的buiid.gradle附近创建文件,但我不知道-如何获取buiid.gradle-file的路径,即放入我的项目.
I need create file in my java-project near buiid.gradle-file. I must create task (Groovy task) in build.gradle-file, my task must create file near buiid.gradle in my project, but I do not know - how do get path to buiid.gradle-file, that is putting in my project.
如何获取Groovy的buiid.gradle文件的完整路径?请帮帮我.
How get full path to file buiid.gradle by Groovy? Help me, please.
推荐答案
有几种方法可以实现此目的.
There are several ways to accomplish this.
- 如果您查看使用文件页面,则可以只需使用作为
Project
对象一部分的file()
方法. - 如果您查看 Project DSL文档,您应该会看到
projectDir
属性.这些属性在整个build.gradle
脚本中都可用.
- If you look at the Working With Files page, you can simply use the
file()
method that is a part of theProject
object. - If you look at the Project DSL Docs, you should see the
projectDir
property. Thes properties are available throughout thebuild.gradle
script.
可以分别使用它们,如下所示:
They can be used, respectively, like this:
task myTask << {
println file('.')
println projectDir
}
将输出
/full/path/to/your/project/
/full/path/to/your/project/
该目录包含任务所在的 build.gradle
文件.
Where that directory contains the build.gradle
file where the task is located.
这篇关于如何获得Groovy的文件build.gradle的完整路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!