Deploying SonarQube 7.8 with Docker and Integrating Alibaba P3C Rules

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

  1. Log in as admin (default password: admin).
  2. Navigate to Quality Profiles and click Create to define a new profile named p3c.
  3. After creation, you'll be redirected to the rule activation page. The new profile starts with zero active rules.
  4. Click Activate More, then search for p3c.
  5. Select all P3C rules, choose Bulk Change → Activate in p3c, and apply.
  6. Return to Quality Profiles, set the p3c profile as default for Java.

Maven Integration

  1. Generate a user token under My Account → Security.
  2. 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>

  1. Run analysis after building your project:
mvn clean package
mvn sonar:sonar

Tags: sonarqube docker Maven Alibaba P3C Java Static Analysis

Posted on Fri, 25 Sep 2026 16:49:08 +0000 by the_last_tamurai