将 gradle.properties 文件放在哪里

我在跟踪人造物 1分钟设置。我已经在本地主机上启动并运行了 ArtiFactory,现在我正试图将它与 Intellij/Gradle 集成。

这个工艺 Web 应用程序提供了一个 gradle.propertiesbuild.gradle文件,所以我试图从将它们添加到我的 IntelliJ 项目开始。但是,我不知道将 gradle.properties文件放在哪里。

我尝试将 gradle.properties内容(键 = 值对)复制到 gradle/wrapper/gradle-wrapper.properties,遗憾的是这样做并不能使键在 build.gradle文件中可访问。有什么想法吗?

161399 次浏览

Gradle looks for gradle.properties files in these places:

  • in project build dir (that is where your build script is)
  • in sub-project dir
  • in gradle user home (defined by the GRADLE_USER_HOME environment variable, which if not set defaults to USER_HOME/.gradle)

Properties from one file will override the properties from the previous ones (so file in gradle user home has precedence over the others, and file in sub-project has precedence over the one in project root).

Reference: https://gradle.org/docs/current/userguide/build_environment.html

Actually there are 3 places where gradle.properties can be placed:

  1. Under gradle user home directory defined by the GRADLE_USER_HOME environment variable, which if not set defaults to USER_HOME/.gradle
  2. The sub-project directory (myProject2 in your case)
  3. The root project directory (under myProject)

Gradle looks for gradle.properties in all these places while giving precedence to properties definition based on the order above. So for example, for a property defined in gradle user home directory (#1) and the sub-project (#2) its value will be taken from gradle user home directory (#1).

You can find more details about it in gradle documentation here.