无法在脚本插件中引用gradle.properties

时间:2015-02-24 16:47:35

标签: gradle ivy artifactory

我正在创建一个脚本插件来引用我的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 文件产生任何进一步的影响。

1 个答案:

答案 0 :(得分: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)