6

有以下内容build.gradle

uploadArchives {
    repositories {
        mavenDeployer {
            repository(url: "$repoUrl") {
                authentication(userName: "$repoUser", password: "$repoPassword")
            }
        }
    }
}

我怎样才能$repoUrl有一个默认值file://$buildDir/repo

我试图repoUrl=file://$buildDir/repo输入gradle.properties,但它没有像我预期的那样工作,因为它似乎$repoUrl没有被递归评估。

4

2 回答 2

2

看起来是因为repoUrl=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 ')
}
于 2013-03-15T09:46:28.403 回答
1

您不能像project.buildDir从属性文件中那样引用 Gradle 属性。属性文件非常有限,一般来说,我建议将所有信息保留在 Gradle 构建脚本中。您可以拥有任意数量的构建脚本,并将它们包含apply from: "path/to/script"在其他脚本中。

于 2013-03-15T09:52:50.030 回答