收藏

eclipse 配置 maven 使用 sonarqube

2023-02-09  本文已影响0人  偷油考拉

maven集成
https://docs.sonarqube.org/9.6/analyzing-source-code/scanners/sonarscanner-for-maven/
jenkins集成
https://docs.sonarqube.org/9.6/analyzing-source-code/scanners/jenkins-extension-sonarqube/
https://www.jenkins.io/doc/pipeline/steps/sonar/

一、准备eclipse上maven的配置文件

image.png

默认不存在 C:\Users\xxx\.m2\settings.xml,需要手动创建一个。设置 sonarqube地址

<settings>
    <pluginGroups>
        <pluginGroup>org.sonarsource.scanner.maven</pluginGroup>
    </pluginGroups>
    <profiles>
        <profile>
            <id>sonar</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <properties>
                <!-- Optional URL to server. Default value is http://localhost:9000 -->
                <sonar.host.url>
                  <!-- http://myserver:9000 -->
                  https://sonar.rha.com
                </sonar.host.url>
            </properties>
        </profile>
     </profiles>
</settings>
image.png

选择配置文件,然后更新。

修改pom.xml文件,增加sonar插件

        <plugin>
          <groupId>org.sonarsource.scanner.maven</groupId>
          <artifactId>sonar-maven-plugin</artifactId>
          <version>3.7.0.1746</version>
        </plugin>
image.png

二、在sonarqube创建用户token

在sonarquebe用户账户下创建token,如下

image.png

sqa_05afc15f0500ae0b3a4eeadafdf97034fa982334

三、在eclipse 的 maven build 配置账户

在Goals配置项,使用sonar.login提交token,如下:
sonar:sonar -Dsonar.login=sqa_05afc15f0500ae0b3a4eeadafdf97034fa982334

image.png

执行成功,显示如下:

...
[INFO] ------------- Run sensors on project
[INFO] Sensor Analysis Warnings import [csharp]
[INFO] Sensor Analysis Warnings import [csharp] (done) | time=1ms
[INFO] Sensor Zero Coverage Sensor
[INFO] Sensor Zero Coverage Sensor (done) | time=9ms
[INFO] Sensor Java CPD Block Indexer
[INFO] Sensor Java CPD Block Indexer (done) | time=23ms
[INFO] SCM Publisher No SCM system was detected. You can use the 'sonar.scm.provider' property to explicitly specify it.
[INFO] CPD Executor Calculating CPD for 1 file
[INFO] CPD Executor CPD calculation finished (done) | time=9ms
[INFO] Analysis report generated in 94ms, dir size=132.2 kB
[INFO] Analysis report compressed in 40ms, zip size=21.3 kB
[INFO] Analysis report uploaded in 39ms
[INFO] ANALYSIS SUCCESSFUL, you can find the results at: https://sonar.rha.com/dashboard?id=com.javatechie.app%3Asonar-example
[INFO] Note that you will be able to access the updated dashboard once the server has processed the submitted analysis report
[INFO] More about the report processing at https://sonar.rha.com/api/ce/task?id=AYY5d6V7Z2WXvBrTrVWs
[INFO] Analysis total time: 7.373 s
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  9.998 s
[INFO] Finished at: 2023-02-10T11:56:42+08:00
[INFO] ------------------------------------------------------------------------

在sonarqube显示如下

image.png

其他

user: admin
sqa_05afc15f0500ae0b3a4eeadafdf97034fa982334

user: core
squ_11eed9721923bc9be311950e7092b4f0e06e84a2

上一篇下一篇

猜你喜欢

热点阅读