首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >不从~/. Gradle /gradle.properties读取Gradle属性

不从~/. Gradle /gradle.properties读取Gradle属性
EN

Stack Overflow用户
提问于 2014-10-13 00:25:41
回答 1查看 4.4K关注 0票数 2

我有一个类似的问题,详见此处:http://gradle.1045684.n5.nabble.com/gradle-gradle-properties-not-being-read-td4372872.html

事实上,这是一个完全相同的问题--只不过那个线程的解决方案对我不起作用。我在OS/X上,使用gradle构建android系统。正在发生的事情的要点是使用以下~/..gradle/gradle.properties文件:

代码语言:javascript
运行
复制
uploadUsername=scottj
uploadKeyFile=/home/scottjohnson/.ssh/uploadKey

以及以下build.gradle文件:

..。跳过普通级和安卓系统的东西.

代码语言:javascript
运行
复制
task checkProperties << {
  if (!hasProperty('uploadUsername')) {
    throw new RuntimeException("Couldn't find uploadUsername property. Did you forget to specify it in ~/.gradle/gradle.properties?")
  } else if (!hasProperty('uploadKeyFile')) {
    throw new RuntimeException("Couldn't find uploadKeyFile property. Did you forget to specify it in ~/.gradle/gradle.properties?")
  }
  println("***** DEBUG_jwir3: " + project.getProperty('uploadUsername'))
}

当我运行./gradlew checkProperties时,我得到:

失败:生成失败,出现异常。

  • 其中:构建文件'/Users/scottjohnson/Source/core-android/crux/build.gradle‘行: 50
  • 哪里出了问题:任务执行失败“:crux:checkProperties”。 找不到uploadUsername属性。您忘记在~/..gradle/gradle.properties中指定它了吗?

  • 尝试:使用--stacktrace选项运行以获得堆栈跟踪。使用--info或-调试选项运行以获得更多日志输出。

构建失败

总时间: 7.072秒

更有趣的是,如果我指定要进行调试日志记录,则会得到以下内容:

代码语言:javascript
运行
复制
mustafar:core-android scottjohnson$ ./gradlew checkProperties -d | grep properties
19:22:35.507 [DEBUG] [org.gradle.initialization.DefaultGradlePropertiesLoader] Found env project properties: []
19:22:35.508 [DEBUG] [org.gradle.initialization.DefaultGradlePropertiesLoader] Found system project properties: []
19:22:35.865 [DEBUG] [org.gradle.initialization.ProjectPropertySettingBuildLoader] Looking for project properties from: /Users/scottjohnson/Source/core-android/buildSrc/gradle.properties
19:22:37.161 [DEBUG] [org.gradle.initialization.DefaultGradlePropertiesLoader] Found env project properties: []
19:22:37.161 [DEBUG] [org.gradle.initialization.DefaultGradlePropertiesLoader] Found system project properties: []
19:22:37.200 [DEBUG] [org.gradle.initialization.ProjectPropertySettingBuildLoader] Looking for project properties from: /Users/scottjohnson/Source/core-android/gradle.properties
19:22:37.200 [DEBUG] [org.gradle.initialization.ProjectPropertySettingBuildLoader] Adding project properties (if not overwritten by user properties): [CORE_GROUP, CORE_VERSION_NAME, CORE_VERSION_CODE]
19:22:37.201 [DEBUG] [org.gradle.initialization.ProjectPropertySettingBuildLoader] Looking for project properties from: /Users/scottjohnson/Source/core-android/crux/gradle.properties

正如您所看到的,它正在识别核心-android/gradle.properties文件(CORE_GROUP、CORE_VERSION_NAME和CORE_VERSION_CODE)中的属性,但我没有看到从~/..gradle/gradle.properties中提取的任何一个属性。

我不想在我的项目的gradle.properties中指定这些属性,因为它们是特定于用户的(推送到私有maven存储库的凭据)。

我做错了什么,导致gradle.properties没有被拉进来?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-10-13 01:49:32

在任务操作中,hasProperty将解析为Task#hasProperty。相反,请使用project.hasProperty(...)

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26331397

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档