Sonar
October 10, 2020

Installation and run

pom.xml

1
2
3
4
5
6
7
8
9
<build>
    <plugins>
        <plugin>
            <groupId>org.sonarsource.scanner.maven</groupId>
            <artifactId>sonar-maven-plugin</artifactId>
            <version>3.10.0.2594</version>
        </plugin>
    </plugins>
</build>

settings.xml

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
<profile>
    <id>sonar</id>
    <activation>
        <activeByDefault>true</activeByDefault>
    </activation>
    <properties>
        <sonar.projectKey>[PROJECT_KEY]</sonar.projectKey>
        <sonar.projectName>[PROJECT_NAME]</sonar.projectName>
        <sonar.host.url>http://localhost:9000</sonar.host.url>
        <sonar.token>[TOKEN]</sonar.token>
        <sonar.exclusions>**/*.py,**/*.css,**/*.scss,**/*.js,**/*.xhtml</sonar.exclusions>
        <!--<sonar.exclusions>**/*.py,**/*.css,**/*.js</sonar.exclusions>-->
        <!--<sonar.scm.provider>git</sonar.scm.provider>-->
        <!--<sonar.organization>aripd</sonar.organization>-->
        <!--<sonar.projectKey>aripd_component-${project.groupId}:${project.artifactId}</sonar.projectKey>-->
        <!--<sonar.moduleKey>${artifactId}</sonar.moduleKey>-->
        <!--<sonar.sourceEncoding>UTF-8</sonar.sourceEncoding>-->
        <!--<sonar.branch.name>main</sonar.branch.name>-->
        <!--<sonar.modules>../component,../component-showcase</sonar.modules>-->
        <!--<sonar.sources>src/main/java</sonar.sources>-->
        <!--<sonar.java.binaries>**/*</sonar.java.binaries>-->
        <!--<sonar.jacoco.reportPath>component/target/jacoco.exec,component-showcase/target/jacoco.exec</sonar.jacoco.reportPath>-->
        <!--<sonar.skip>true</sonar.skip>-->
    </properties>
</profile>

docker-compose.yml

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
    sonarqube:
        image: sonarqube:community
        ulimits:
          nofile:
            soft: "65536"
            hard: "65536"
        volumes:
          - /tmp/opt/sonarqube/conf:/opt/sonarqube/conf \
          - /tmp/opt/sonarqube/logs:/opt/sonarqube/data \
          - /tmp/opt/sonarqube/data:/opt/sonarqube/logs \
          - /tmp/opt/sonarqube/extensions:/opt/sonarqube/extensions \
        ports:
          - "9000:9000"

To up sonarqube container

1
2
docker compose up -d
docker compose -f docker-compose.yml up -d

Go to sonar.host.url which is http://localhost:9000 as written settings.xml

The default user with Administer System permission is admin, and the password: admin

Enter PROJECT_NAME, PROJECT_KEY, branch name and then generate TOKEN. After that enter them to settings.xml

To run sonar

1
mvn clean verify sonar:sonar

To down sonarqube container

1
2
docker compose down -v
docker compose -f docker-compose.yml down -v