docker 容器的创建
docker run -d --name sonar -p 9000:9000 -e sonar.jdbc.username=root -e sonar.jdbc.password=root -e sonar.jdbc.url=jdbc:mysql://172.17.0.4:3306/sonar?useUnicode=true'&'characterEncoding=utf8'&'useSSL=false sonarqube
项目pom.xml配置
<properties>
<jacoco.plugin.version>0.8.3</jacoco.plugin.version>
</properties>
<profiles>
<profile>
<id>sonar</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<sonar.host.url>http://localhost:9000</sonar.host.url>
</properties>
</profile>
</profiles>
<build>
<plugins>
<!-- sonar 扫描,代码覆盖率插件 -->
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco.plugin.version}</version>
<configuration>
<append>true</append>
</configuration>
<executions>
<execution>
<id>jacoco-ut</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>jacoco-it</id>
<goals>
<goal>prepare-agent-integration</goal>
</goals>
</execution>
<execution>
<id>jacoco-site</id>
<phase>verify</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
maven 命令
实例:
mvn clean package sonar:sonar -Dsonar.host.url=http://localhost:9000
// 项目key
sonar.projectKey=demoKey
// 项目名称
sonar.projectName=demoName
// sonar服务器地址
sonar.host.url=http://localhost:9000
// 用户名/token
sonar.login=admin
// 密码(token不需要此项)
sonar.password=admin
// 测试类出错时,不停止,继续跑
maven.test.failure.ignore=true