我正在尝试使用gradle实现声纳,以实现我的项目的代码覆盖率测量。我们正在使用gradle-4.0.1和sonarqube-6.4。
当我从命令行运行gradle sonarqube时,出现此错误-
Plugin with id 'org.sonarqube' not found.
我尝试了一些代码更改,但没有运气,请帮忙。我的build.gradle文件如下-
buildscript { ext { springBootVersion = '1.5.4.RELEASE' } repositories { mavenCentral() } dependencies { classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}") } } apply plugin: 'org.sonarqube' apply plugin: "jacoco" apply plugin: "java" apply plugin: "war" apply plugin: "org.springframework.boot" sonarqube { properties { property "sonar.projectName","Spring4WebService Code Coverage Demo" property "sonar.projectKey", "org.sonarqubeJacocoCodeCoverage" property "sonar.reportPath" , "${project.buildDir}/jacoco/test.exec" } } test{ ignoreFailures = true } ext { jacocoVersion = '0.7.6.201602180812' } sourceCompatibility = 1.8 targetCompatibility = 1.8 repositories { mavenCentral() } sourceSets { main.java.srcDir "src/main/java" test.java.srcDir "src/test/java" } springBoot { mainClass = "com.concretepage.config.WebAppInitializer" } dependencies { compile('org.springframework.boot:spring-boot-starter-web','com.fasterxml.jackson.core:jackson-databind') testCompile('org.springframework.boot:spring-boot-starter-test') } jacoco{ toolVersion = "${jacocoVersion}" } jacocoTestReport { reports{ html.enabled=true xml.enabled=true csv.enabled=true } }
就像'org.springframework.boot'插件一样,该'org.sonarqube'插件不属于Gradle。它是一个第三方插件,因此您需要将其添加为buildscript依赖项:
'org.springframework.boot'
'org.sonarqube'
buildscript
buildscript { ext { springBootVersion = '1.5.4.RELEASE' } repositories { mavenCentral() maven { url "https://plugins.gradle.org/m2/" } } dependencies { classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}") classpath "org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:2.5" } }
现在apply plugin: 'org.sonarqube'应该工作正常。
apply plugin: 'org.sonarqube'