Intellij + Gradle:属性文件(Intellij + Gradle: properties file)

编程入门 行业动态 更新时间:2024-10-27 17:09:29
Intellij + Gradle:属性文件(Intellij + Gradle: properties file)

我的配置:

Gradle通过Homebrew(Mac OS)安装,Intellij Idea 13。

优先:

“使用默认的Gradle包装器”和gradle home: /Users/my_username/.gradle


对于以下项目:

/ build.gradle gradle.properties

gradle.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.properties

The 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=Hello

gradle.properties

NAME = PJ

的build.gradle

task hello << { println TEST println NAME }

当gradle hello运行时,我得到以下输出:

:hello Hello PJ BUILD SUCCESSFUL Total time: 2.992 secs

With gradle 2.0 it works perfectly fine:

$HOME/.gradle/gradle.properties

TEST=Hello

gradle.properties

NAME = PJ

build.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

更多推荐

本文发布于:2023-07-30 13:20:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1337872.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:属性   文件   Gradle   Intellij   properties

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!