我的配置:
Gradle通过Homebrew(Mac OS)安装,Intellij Idea 13。
优先:
“使用默认的Gradle包装器”和gradle home: /Users/my_username/.gradle
对于以下项目:
/ build.gradle gradle.propertiesgradle.properties文件包含变量NAME = PJ 。 我还在/Users/my_username/.gradle/gradle.properties下有一个gradle.properties, /Users/my_username/.gradle/gradle.properties有一个变量TEST=Hello 。
对于给定的任务,gradle打印Hello和null
task hello << { println TEST println NAME }这意味着默认情况下它不会读取同一目录中的gradle.properties。 这是正常的行为还是我错过了路径变量中的内容,那么build.gradle脚本可以读取它吗?
我找到的解决方法是添加:
file("gradle.properties").withInputStream { stream -> new Properties().load(stream) }当我使用android studio时,自动导入同一目录的.properties文件。
PS:虽然TEST var被打印,但我收到一条Cannot resolve symbol的警告。 我看到了,这是典型的错误(?)。
My configuration:
Gradle installed via Homebrew (Mac OS), Intellij Idea 13.
Preferences:
"Use default Gradle wrapper" and gradle home: /Users/my_username/.gradle
For the following project:
/ build.gradle gradle.propertiesThe gradle.properties file contains a variable NAME = PJ. I also have a gradle.properties under /Users/my_username/.gradle/gradle.properties having a variable TEST=Hello.
For the given task, gradle prints Hello and null
task hello << { println TEST println NAME }Which means that it does not read by default the gradle.properties in the same directory. Is it a normal behavior or do I miss something in path variable so can the build.gradle script can read it?
A work-around I found is to add:
file("gradle.properties").withInputStream { stream -> new Properties().load(stream) }When I used android studio the .properties file of the same dir was automatically imported.
PS: Although TEST var gets printed I get a warning for Cannot resolve symbol. I saw around and this is typical error (?).
最满意答案
使用gradle 2.0它可以完美地运行:
$ HOME / .gradle / gradle.properties
TEST=Hellogradle.properties
NAME = PJ的build.gradle
task hello << { println TEST println NAME }当gradle hello运行时,我得到以下输出:
:hello Hello PJ BUILD SUCCESSFUL Total time: 2.992 secsWith gradle 2.0 it works perfectly fine:
$HOME/.gradle/gradle.properties
TEST=Hellogradle.properties
NAME = PJbuild.gradle
task hello << { println TEST println NAME }When gradle hello run I get the following output:
:hello Hello PJ BUILD SUCCESSFUL Total time: 2.992 secs更多推荐
发布评论