Gradle:从中获取“gradle”的文件夹被执行 [英] Gradle: get folder from which "gradle" was executed

查看:122
本文介绍了Gradle:从中获取“gradle”的文件夹被执行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图将gradle任务用作OS不可知的shell脚本。我在编写构建文件的逻辑时没有问题,但我希望能够从任何文件夹运行它。



我的第一个尝试是将一个文件夹与我的build.gradle文件在路径上,然后尝试执行:

  gradle myMask 


$ b $ p

从不包含build.gradle的文件夹 - 但不起作用。



我的下一次尝试是:

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

但是这只起到了一定的作用。在我的任务中,我想查找CURRENT DIRECTORY中的所有文件。当前 - 意思不是包含build.gradle,而是执行其中的一个gradle .....。

我试过了:

  file(。)



  file($ projectDir)

等等,但它们全都指向包含构建脚本的文件夹,不包含来自
的文件夹,我正在执行它。



任何想法我该怎么做?

解决方案

获胜者是:

  System.getProperty(user.dir)


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?

解决方案

and the winner is:

System.getProperty("user.dir")

这篇关于Gradle:从中获取“gradle”的文件夹被执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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