Properties 正确设置渐变属性的默认值
在Properties 正确设置渐变属性的默认值,properties,groovy,gradle,Properties,Groovy,Gradle,在build.gradle中具有以下内容: uploadArchives { repositories { mavenDeployer { repository(url: "$repoUrl") { authentication(userName: "$repoUser", password: "$repoPassword") } } } } 如何使$repoUrl具
build.gradle
中具有以下内容:
uploadArchives {
repositories {
mavenDeployer {
repository(url: "$repoUrl") {
authentication(userName: "$repoUser", password: "$repoPassword")
}
}
}
}
如何使$repoUrl
具有默认值文件://$buildDir/repo
我试图将
repoorl=file://$buildDir/repo
放在gradle.properties
中,但它没有像我预期的那样工作,因为$repoorl
似乎不是递归计算的。看起来像是因为repoorl=file://$buildDir/repo
被视为普通字符串,没有buildDir
替换
如果你可以试试这个:
repository(url:repoUrl.replace(“$buildDir”,“$buildDir”){
或者像这样:
// run as 'gradle build -PreportUrl=blabla'
def repoUrl = "file://$buildDir/repo"
if (binding.variables.containsKey('repoUrl ')) {
repoUrl = binding.variables.get('repoUrl ')
}
您不能从属性文件中引用诸如
project.buildDir
之类的Gradle属性。属性文件非常有限,一般来说,我建议将所有信息保存在Gradle构建脚本中。您可以拥有任意数量的构建脚本,并将其包含在应用自:“路径/到/脚本”中
在其他脚本中。我对gradle的一个惊喜是,~/.gradle/gradle.properties
优先于/gradle.properties
,因为我坚持gradle.properties:)有没有办法在build.gradle
中为属性指定默认值并在~/.gradle/gradle.properties
中重写它?生成脚本中只有两个属性和一些逻辑。(属性文件在生成脚本之前进行评估。)键入:…替换(“$buildDir”,“$buildDir”)…