Version Compatibility Notes
SonarQube version 7.8-community is the final release compatible with JDK 1.8. Starting from version 7.9, SonarQube requires JDK 11 or higher and drops support for MySQL in favor of PostgreSQL.
System Configuration for Embedded Elasticsearch
Because SonarQube includes an embedded Elasticsearch instance, certain OS-level settings must be adjusted:
# /etc/security/limits.conf
* soft nofile 65535
* hard nofile 65535
* soft nproc 4096
* hard nproc 4096
# /etc/sysctl.conf
vm.max_map_count=262144
Apply the changes with:
sysctl --system
Docker Compose Setup
Using Embedded Database
version: "3.6"
services:
sonarqube:
image: sonarqube:7.8-community
restart: always
ports:
- "9000:9000"
volumes:
- ./sonar-data:/opt/sonarqube/data
- ./plugins/sonar-pmd-plugin-3.2.0.jar:/opt/sonarqube/extensions/plugins/
- ./plugins/sonar-l10n-zh-plugin-1.28.jar:/opt/sonarqube/extensions/plugins/
Using External MySQL (for v7.8 only)
version: "3.6"
services:
sonarqube:
image: sonarqube:7.8-community
restart: always
ports:
- "9000:9000"
environment:
- SONAR_JDBC_URL=jdbc:mysql://192.168.33.12:3306/sonar?useSSL=false&serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf8&autoReconnect=true&rewriteBatchedStatements=true&allowMultiQueries=true
- SONAR_JDBC_USERNAME=sonar
- SONAR_JDBC_PASSWORD=sonar
volumes:
- ./sonar-data:/opt/sonarqube/data
- ./plugins/sonar-pmd-plugin-3.2.0.jar:/opt/sonarqube/extensions/plugins/
- ./plugins/sonar-l10n-zh-plugin-1.28.jar:/opt/sonarqube/extensions/plugins/
Configuring Alibaba P3C as Default Java Quality Profile
- Log in as
admin(default password:admin). - Navigate to Quality Profiles and click Create to define a new profile named
p3c. - After creation, you'll be redirected to the rule activation page. The new profile starts with zero active rules.
- Click Activate More, then search for
p3c. - Select all P3C rules, choose Bulk Change → Activate in p3c, and apply.
- Return to Quality Profiles, set the
p3cprofile as default for Java.
Maven Integration
- Generate a user token under My Account → Security.
- Add the following to your project’s
pom.xml:
<properties>
<java.version>1.8</java.version>
<sonar.host.url>http://192.168.33.12:9000/</sonar.host.url>
<sonar.login>your-generated-token-here</sonar.login>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.sonarsource.scanner.maven</groupId>
<artifactId>sonar-maven-plugin</artifactId>
<version>3.9.1.2184</version>
</plugin>
</plugins>
</build>
- Run analysis after building your project:
mvn clean package
mvn sonar:sonar