For a while now I’ve wanted to install SonarQube for doing static analysis of my Java EE 7 applications. The current downloadable version of SonarQube is 5.1.1. The SonarQube requirements documentation indicates that SonarQube supports the following RDBMS for its repository:
- Microsoft SQL Server 2008 and 2012;
- Oracle 10g and 11g;
- MySQL 5.1, 5.5, 5.6, and 5.7;
- PostgreSQL 8.x and 9.x.
Since I’ve now migrated to Oracle 12c, I thought I would attempt installing SonarQube with Oracle 12c Enterprise Edition 188.8.131.52.0 64-bit on Windows 7.
Setting up the database
SonarQube uses a database system to store metadata about the software projects that it analyzes. Running SonarQube for the first time will create and populate all of the necessary tables; the userid used by the SonarQube process must be able to create various types of objects in the database, including indexes. With Oracle 12c I created a separate pluggable database for Sonarqube. I created a separate user with the DBA role for myself, and a separate user, “sonarqube”, for use by the SonarQube process. To permit the sonarqube account to create all of its necessary objects without issues – there is no documentation outlining precisely what is required – I granted the sonarqube Oracle account a variety of privileges:
1 2 3 4 5 6 7 8 9 10 11 12
GRANT CREATE TABLE TO sonarqube; GRANT CREATE VIEW, CREATE SYNONYM, CREATE SEQUENCE TO sonarqube; GRANT CREATE TABLESPACE, ALTER TABLESPACE, DROP TABLESPACE, MANAGE TABLESPACE TO sonarqube; GRANT CREATE TRIGGER TO sonarqube; GRANT CREATE PROCEDURE, EXECUTE ANY PROCEDURE TO sonarqube; GRANT CREATE SESSION, ALTER SESSION TO sonarqube; GRANT CREATE MATERIALIZED VIEW TO sonarqube; GRANT CREATE ANY INDEX TO sonarqube; GRANT CREATE TYPE, EXECUTE ANY TYPE TO sonarqube; GRANT DEBUG CONNECT SESSION TO sonarqube; GRANT DEBUG ANY PROCEDURE TO sonarqube; ALTER USER sonarqube QUOTA UNLIMITED ON SYSTEM;
What also isn’t clear is if SonarQube uses custom DDL statements for each underlying DBMS, or if it relies on Hibernate to issue the DDL. SonarQube 5.1.1 itself contains three object-relational mapping toolkits within its software suite: Java Hibernate 3.3.2, iBatis 3.2.7, and JRuby 1.7.9.
The SonarQube 5.1.1 install couldn’t be easier – one simply unzips the .zip archive. However, before one can move forward with Oracle 12c there are a number of things to take care of. Most of these involve editing either the sonar.properties or the wrapper.conf files in
I edited wrapper.conf to explicitly specify the location of my 64-bit Java 7 SDK. Note that one cannot (merely) specify the directory of the JDK; what SonarQube requires is the complete path to java.exe. My edit looks like:
The sonar.properties file requires a number of edits. For Oracle 12c, the required changes are the userid/password combination for the sonarqube account, along with the JDBC URL. My installation uses the following:
2 3 4
sonar.jdbc.username=sonarqube sonar.jdbc.password=XXXXXXX sonar.jdbc.url=jdbc:oracle:thin:@//localhost:1521/sonarqube
Line 4 requires some explanation. Oracle 12c supports “servicename” as a variant for a JDBC URL. As I’ve setup a pluggable database for SonarQube, the PDB name “sonarqube” becomes the servicename in the URL. Note that the leading “//” in the URL are not optional.
I also uncommented a number of settings related to JDBC connection pooling:
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
#----- Connection pool settings # The maximum number of active connections that can be allocated # at the same time, or negative for no limit. sonar.jdbc.maxActive=50 # The maximum number of connections that can remain idle in the # pool, without extra ones being released, or negative for no limit. sonar.jdbc.maxIdle=5 # The minimum number of connections that can remain idle in the pool, # without extra ones being created, or zero to create none. sonar.jdbc.minIdle=2 # The maximum number of milliseconds that the pool will wait (when there # are no available connections) for a connection to be returned before # throwing an exception, or <= 0 to wait indefinitely. sonar.jdbc.maxWait=5000
In addition to specifying the Oracle connection parameters, I modified the sonar.properties file in a number of other ways:
- I explicitly set the port numbers for SonarQube’s embedded Tomcat server, which with the 5.1.1 SonarQube release is Tomcat 8.0.18:
The default SonarQube port is 9000, and is properly reserved. However, the default search port with SonarQube is 9001, which conflicts with Microsoft Sharepoint; so I set it to 9005 instead.
- Logging is turned off by default. Logging should be turned on, because otherwise if one has issues with the installation or setup you will have no idea what has occurred, because the SonarQube process will (likely) simply fail to start and you won’t know why.
24 25 26
sonar.path.logs=logs sonar.log.rollingPolicy=size:10MB sonar.log.maxFiles=7
Finally, I copied my Oracle 184.108.40.206 JDBC driver, ojdbc7.jar, from the Oracle server’s product/12.1.0/dbhome_1/jdbc/lib directory and placed it in the SonarQube directory /extensions/jdbc-driver/oracle as per the installation guide.
With these settings, starting the SonarQube 5.1.1 64-bit executable using the included StartSonar.bat file worked well. The SonarQube process started a JVM instance, connected to the Oracle 12c database, and created all of its tables for project metadata, which I confirmed by connecting to the PDB via SQL Developer. With the message that the SonarQube Tomcat server was up:
I opened a Chrome browser and tried to get to the SonarQube server’s home page. Alas, what I got was this:
Fortunately, this null pointer exception problem with Oracle’s JDBC driver in method oracle.jdbc.driver.AutoKeyInfo.initMetaDataColumnIndexes is a known issue and is fixed in version 220.127.116.11 of the Oracle JDBC drivers, which has just been released and can be found here. With the patched JDBC driver copied to the SonarQube /extensions directory, I now have a properly-working SonarQube server.
- Get the latest patches for Oracle’s JDBC drivers.
- Turn on logging with your SonarQube installation.
- There doesn’t seem to be any issues with using SonarQube 5.1.1 with Oracle 12c.