我正在尝试在Java项目的Gradle构建脚本中包含类路径依赖项。我有gradle.properties
个文件,其中列出了两个变量:nexusUsername
和nexusPassword
。这两个都以与buildcript存储库相同的方式在项目根存储库中使用,并且它工作正常 - 依赖项被加载。
但是,在配置这样的buildscript时:
buildscript {
repositories {
maven {
credentials {
username nexusUsername
password nexusPassword
}
url 'https://edited'
}
}
dependencies {
classpath 'edited'
}
}
我收到这样的错误:
Could not GET 'https://edited.pom'. Received status code 403 from server: Forbidden
访问带有身份验证的浏览器提供的URL。
到目前为止,我能够弄清楚构建脚本在构建的最初阶段进行评估,因此,属性可能尚未加载?如果这是真的,如何加载它们?
答案 0 :(得分:0)
显然,问题是在运行之间的gradle.properties
中意外地在密码末尾放置了额外的符号。工作正常。
答案 1 :(得分:0)
解决方法如果要使用替代属性文件,例如local.properties,gradle-local.properties :
1º)在项目rootdir中,添加新文件“ add-custom-properties.gradle”:
Properties props = new Properties()
props.load(new FileInputStream("$rootDir/gradle-local.properties"))
props.each { prop ->
ext.set(prop.key, prop.value)
}
如果需要,可以在此以前的脚本中添加逻辑。
2º)编辑/创建gradle-local.properties
repoUrl=https://a-url...
repoUser=a-user
repoPass=a-pass
3º)在build.gradle中,settings.xml,...(在buildscript {...}内部):
buildscript {
apply from: "$rootDir/add-custom-properties.gradle"
repositories {
maven {
url = "${repoUrl}"
credentials {
username = "${repoUser}"
password = "${repoPass}"
}
}
}