我正在嘗試創建2個任務來執行sonarcube任務。我希望能夠指定取決於對於不同的任務,不能具有不同的系統屬性值
task sonarqubePullRequest(type: Test){
System.setProperty("sonar.projectName", "sonarqubePullRequest")
System.setProperty("sonar.projectKey", "sonarqubePullRequest")
System.setProperty("sonar.projectVersion", serviceVersion)
System.setProperty("sonar.jacoco.reportPath",
"${project.buildDir}/jacoco/test.exec")
tasks.sonarqube.execute()
}
task sonarqubeFullScan(type: Test){
System.setProperty("sonar.projectName", "sonarqubeFullScan")
System.setProperty("sonar.projectKey", "sonarqubeFullScan")
System.setProperty("sonar.projectVersion", serviceVersion)
System.setProperty("sonar.jacoco.reportPath",
"${project.buildDir}/jacoco/test.exec")
tasks.sonarqube.execute()
}
任務的工作任務,不同的性質,但似乎與我設置
如果我運行的第一個任務是sonarqubePullRequest那麼性能的問題一切都很好,但如果運行sonarqubeFullScan,那麼如果使用sonarqubePullRequest中指定的值。所以項目名稱設置sonarqubePullRequest
它就好像這些屬性是在運行時設置的並且無法更新。我覺得我錯過了很明顯的任何建議,大大收到。
偉大的答案,有一個問題我怎麼在傳遞一個條件,如「全掃描」會是這樣通過命令行'gradle sonarqube fullScan'? – JaChNo
項目屬性通過'-P = '來設置。因此,對於上面的代碼示例,您可以指定'-PfullScan = true'。你也可以通過檢查hasProperty('fullScan')來使用項目屬性的存在性作爲條件。在這種情況下,'-PfullScan'就足夠了。 –