我的项目依赖项之一位于私有Bintray存储库上,该存储库需要用户名和密码才能访问。在本地,我将这些设置为gradle.properties
:
bintrayUsername=<myUserName>
bintrayPassword=<myPass>
这可以(在本地)有效,其中hasProperty(X)
解析为true并使用以下属性:
allprojects {
repositories {
jcenter()
def mahBintrayUsername = hasProperty(bintrayUsername) ? bintrayUsername : System.getenv('bintrayUsername')
def mahBintrayPassword = hasProperty(bintrayPassword) ? bintrayPassword : System.getenv('bintrayPassword')
maven {
credentials {
username mahBintrayUsername
password mahBintrayPassword
}
url 'http://dl.bintray.com/my-repo-org/maven-private'
}
}
}
在Travis上,我使用安全变量,因此不必在公共存储库中公开这些值,而是旨在能够直接从公共存储库构建。开始构建时,您可以看到已导出变量:
Setting environment variables from .travis.yml
$ export bintrayUsername=[secure]
$ export bintrayPassword=[secure]
$ export TERM=dumb
...
FAILURE: Build failed with an exception.
* Where:
Build file '/home/travis/build/ataulm/wutson/build.gradle' line: 15
* What went wrong:
A problem occurred evaluating root project 'wutson'.
> Could not find property 'bintrayUsername' on repository container.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
我不确定如何引用导出的环境变量以build.gradle
找到它们。
我检查了这个似乎无效的答案(如上所述),以及导致相同构建失败的注释。
我尝试过的一系列提交都可以在这里看到,并提供最新的提交:https : //github.com/ataulm/wutson/commit/9331b8d91b4acf11fd3e286ff8ba1a24ed527177
该错误是由于您的三元语句试图bintrayUsername
作为条件的一部分进行评估而导致的。
该hasProperty()
方法带有一个String
参数,因此您应该使用hasProperty('bintrayUsername')
而不是hasProperty(bintrayUsername)
。进行后者将尝试评估可能不存在的属性,从而导致MissingPropertyException
。
只需记住,尝试评估不存在的任何符号通常会导致MissingPropertyException
。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句