Jiang LiHeng Good is good, but better carries it.

SonarQube + Maven 进行代码分析

2020-06-14
jiangliheng
本文 1128 字,阅读全文约需 4 分钟

安装设置

参见之前的文章:

分析权限设置

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

-w1346

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

报告

-w1375

-w1349

微信公众号:daodaotest


作者:Jiang LiHeng
原文链接:https://jiangliheng.github.io/2020/06/14/sonar-maven/
本文版权归作者所有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文链接。


Similar Posts

Comments