簡體   English   中英

正確設置gradle屬性的默認值

[英]Properly set defaults for gradle properties

build.gradle具有以下build.gradle

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

如何讓$repoUrl有一個默認值file://$buildDir/repo

我試圖把repoUrl=file://$buildDir/repogradle.properties ,但我希望這是行不通的,因為它似乎$repoUrl不遞歸評估。

看起來是因為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 ')
}

您無法從屬性文件中引用Gradle屬性,如project.buildDir 屬性文件非常有限,一般來說,我建議將所有信息保存在Gradle構建腳本中。 您可以擁有任意數量的構建腳本,並在其他腳本中使用apply from: "path/to/script"包含它們。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM