我正在尝试创建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'就足够了。 –