将Maven与多模块项目一起使用时,我只需将Sonar插件添加到父POM中即可:
<plugin>
<groupId>org.sonarsource.scanner.maven</groupId>
<artifactId>sonar-maven-plugin</artifactId>
<version>3.4.0.905</version>
</plugin>
然后在项目根目录中运行它以获得汇总结果:
.../project$ mvn sonar:sonar
或者针对特定模块:
.../project$ mvn sonar:sonar -f module/pom.xml
然而,Gradle似乎无法做到这一点。
如果我只在根项目中应用SonarQube插件(apply plugin: 'org.sonarqube'
),则在根项目中运行时会得到聚合结果,但子项目中没有该插件:
.../project$ ./gradlew :module:sonarqube
FAILURE: Build failed with an exception.
* What went wrong:
Task 'sonarqube' not found in project ':module'.
...
如果我只在子项目中应用SonarQube插件,则在根项目上运行它并不会给出汇总结果。
如果我在allprojects(根项目+子项目)中应用SonarQube插件,尝试运行任何Gradle命令输出:
FAILURE: Build failed with an exception.
* Where:
Build file '.../project/build.gradle' line: 38
* What went wrong:
A problem occurred evaluating root project 'project'.
> Failed to apply plugin [id 'org.sonarqube']
> Cannot add extension with name 'sonarqube', as there is an extension already registered with that name.
有没有办法让Gradle的SonarQube插件在根项目和子项目中都能像Maven一样工作?