【问题标题】:Unable to reference gradle.properties in script plugin无法在脚本插件中引用 gradle.properties
【发布时间】:2015-04-26 09:55:24
【问题描述】:

我正在创建一个脚本插件来引用包含我的 orgs gradle 插件的 ivy 存储库。我现在的代码是:

repository.gradle

repositories {
    ivy {
       credentials {
            username = artifactory_user
            password = artifactory_password
        }
        url 'https://ourUrl/artifactory/repoName'
        layout "pattern", {
            ivy '[organization]/[module]/[revision]/ivy-[revision].xml'
            artifact '[organisation]/[module]/[revision]/[artifact]-[revision].[ext]'
        }
    }
}

然后,在 build.gradle 文件中,

build.gradle

buildscript {
    apply from: https://ourUrl/assets/repository.gradle, to: buildscript
    dependencies { classpath group: 'ourGrp', name: 'artifactName', version: '1.0.0' }
}

在我的 gradle.properties 文件中:

gradle.properties

artifactory_user=username
artifactory_password=password

我收到的错误信息是这样的:

What went wrong:
A problem occurred evaluating script.
Could not find property 'artifactory_user' on Credentials [username: null].

关于如何解决此问题的任何建议?如果可能的话,我想避免对 build.gradle 文件产生任何进一步的影响。

【问题讨论】:

  • 您可以尝试用project. artifactory_user 引用artifactory_user 吗?
  • gradle.properties 文件位于我的 Gradle 用户主目录中,而不是项目主目录中。我已经确认使用 --info 在构建中正确获取了 gradle 用户主页。
  • 好的,刚刚尝试更改为,我收到消息:在凭据 [用户名:null] 上找不到属性“项目”。

标签: gradle ivy artifactory


【解决方案1】:

This exact question was asked in the gradle forums。我将粘贴有效的解决方法,这样它就不会在重新链接或其他什么过程中丢失:

repository.gradle:

repositories {
    ivy {
       credentials {
            username = artifactory_user
            password = artifactory_password
        }
        url 'https://ourUrl/artifactory/repoName'
        layout "pattern", {
            ivy '[organization]/[module]/[revision]/ivy-[revision].xml'
            artifact '[organisation]/[module]/[revision]/[artifact]-[revision].[ext]'
        }
    }
}
ext.extRepo = repositories

build.gradle:

buildscript {scriptHandler->
  apply from: 'https://ourUrl/assets/repository.gradle'
  repositories.addAll(extRepo)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-11-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-26
    • 1970-01-01
    相关资源
    最近更新 更多