【问题标题】:Gradle properties not being read from ~/.gradle/gradle.properties未从 ~/.gradle/gradle.properties 读取 Gradle 属性
【发布时间】:2014-12-07 12:15:33
【问题描述】:

我有一个类似的问题,如下所述: http://gradle.1045684.n5.nabble.com/gradle-gradle-properties-not-being-read-td4372872.html

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

uploadUsername=scottj
uploadKeyFile=/home/scottjohnson/.ssh/uploadKey

还有以下 build.gradle 文件:

...跳过了一般的 gradle 和特定于 android 的东西...

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 时,我得到:

FAILURE:构建失败并出现异常。

  • 在哪里: 构建文件“/Users/scottjohnson/Source/core-android/crux/build.gradle”行:50

  • 出了什么问题: 任务 ':crux:checkProperties' 执行失败。

    找不到uploadUsername 属性。你忘记在 ~/.gradle/gradle.properties 中指定了吗?

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

构建失败

总时间:7.072 秒

更有趣的是,如果我指定要调试日志记录,我会得到以下信息:

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

如您所见,它正在识别 core-android/gradle.properties 文件中的属性(CORE_GROUP、CORE_VERSION_NAME 和 CORE_VERSION_CODE),但我看不到 ~/.gradle/gradle.properties 中的任何一个属性被拉进去了。

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

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

【问题讨论】:

    标签: android maven properties gradle


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2016-12-26
      • 1970-01-01
      • 2018-04-15
      • 2022-11-04
      • 1970-01-01
      • 2014-06-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多