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

Unable to reference gradle.properties in script plugin

我正在创建一个脚本插件来引用包含我的组织 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 文件造成任何进一步的影响。

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)