参见之前的文章:

分析权限设置

为了分析方便,这里设置了一个 sonar 用户,默认配置到 Maven 的 settings.xml 中,用于 Jenkins 或者本地执行 Sonar 分析代码使用,当然也可以配置具有执行分析权限的用户。

SonarQube + Maven 进行代码分析

Maven 设置

settings.xml

$ cat settings.xml
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
    ......
    <pluginGroups>
        <pluginGroup>org.sonarsource.scanner.maven</pluginGroup>
    </pluginGroups>
    .....
    <profile>
      <id>sonar</id>

      <activation>
        <activeByDefault>true</activeByDefault>
      </activation>

      <properties>
        <sonar.host.url>https://xxx.com/sonar</sonar.host.url>
        <!-- 具有执行分析权限的用户名和密码 -->
        <sonar.login>sonar</sonar.login>
        <sonar.password>xxxxxx</sonar.password>
      </properties>
    </profile>
  </profiles>
  ......
</settings>

分析

# 执行 sonar 代码分析,跳过单元测试
$ mvn clean verify sonar:sonar -Dmaven.test.skip=true

# 配合 Maven 的 -pl、-am 参数,实现模块代码分析
$ mvn clean verify sonar:sonar -pl nait-per -am

报告

SonarQube + Maven 进行代码分析

SonarQube + Maven 进行代码分析

微信公众号:daodaotest

相关文章:

  • 2021-10-06
  • 2022-12-23
  • 2021-09-10
  • 2022-01-03
  • 2021-10-25
  • 2021-06-07
  • 2021-12-27
猜你喜欢
  • 2021-06-22
  • 2021-12-20
  • 2021-08-09
  • 2021-09-20
  • 2021-10-08
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案