SonarQube 是一个开源平台,用于持续检测代码质量并管理代码质量。它通过静态分析检测代码缺陷、安全漏洞,并生成详细报告。支持多种编程语言,提供社区版和企业版,通过可操作的洞察提升代码质量、可维护性和安全性。本文介绍在Ubuntu 24.04上安装SonarQube的步骤,并通过示例项目进行代码质量检测。
SonarQube需要PostgreSQL存储数据,Ubuntu默认软件源已包含PostgreSQL。按以下步骤安装并配置数据库:
安装PostgreSQL(若未安装)
$ sudo apt install -y postgresql-common postgresql -y
启用开机自启
$ sudo systemctl enable postgresql
输出:
Synchronizing state of postgresql.service with SysV service script with /usr/lib/systemd/systemd-sysv-install.
Executing: /usr/lib/systemd/systemd-sysv-install enable postgresql
启动数据库服务
$ sudo systemctl start postgresql