Skip to main content

Scanning code

Run the analysis with the SonarScanner CLI. PL/SQL projects have no standard layout or build tool, so you tell the scanner where the files are in a sonar-project.properties file at the project root:

sonar.projectKey=my-plsql-project
sonar.sources=src
# Optional: utPLSQL test packages, analyzed by the test rules
sonar.tests=test

Then run sonar-scanner from the project root. The Getting started guide shows the complete flow.

Parameters​

Most projects only need to adjust the file suffixes:

ParameterDescriptionDefault
sonar.plsqlopen.file.suffixesComma-separated suffixes of the PL/SQL files to analyze.sql,pkg,pks,pkb
sonar.zpa.forms.metadataOracle Forms metadata file. See Oracle Forms support.
sonar.zpa.tests.reportPathsutPLSQL test execution reports. See Importing utPLSQL reports.utplsql-test.xml
sonar.zpa.coverage.reportPathsutPLSQL coverage reports. See Importing utPLSQL reports.utplsql-coverage.xml
sonar.zpa.oracle.*Connection to an Oracle database to read table, view and synonym definitions. See Database metadata.
sonar.zpa.oracle.compilationSchema, sonar.zpa.schemaPathsSchema in which the units compile. See Compilation schema.
sonar.zpa.ccflagsPLSQL_CCFLAGS the code is compiled with. See Conditional compilation.
sonar.zpa.databaseVersionDatabase version the code is compiled for. See Conditional compilation.

Advanced parameters, rarely changed:

ParameterDescriptionDefault
sonar.zpa.errorRecoveryEnabledSkip statements that cannot be parsed and keep analyzing the file. See Error recovery.true
sonar.zpa.concurrentExecutionAnalyze files in parallel.true

Conditional compilation​

By default ZPA doesn't evaluate $IF conditions: it analyzes the first branch of each $IF and skips branches that only contain $ERROR. To analyze the branches the database would compile, set the flags and the database version the code is compiled with:

sonar.zpa.ccflags=debug:FALSE, level:2
sonar.zpa.databaseVersion=19

With either parameter set, ZPA evaluates $$ inquiry directives (a flag that is not set is null) and the DBMS_DB_VERSION constants (VERSION, RELEASE, VER_LE_19…). A condition ZPA can't evaluate, such as one that calls a package constant, falls back to the first branch from that point on. When ZPA reads database metadata and sonar.zpa.databaseVersion is not set, it uses the version of the connected database. An invalid value fails the analysis.

Resolving issues from comments​

A sonar-resolve comment on a line marks the issues of the listed rules on that line as accepted or as false positives, with a justification that SonarQube records:

begin
null; -- sonar-resolve [fp] plsql:EmptyBlock the archive hook is filled at deployment
end;

The comment reads sonar-resolve [status] rules justification:

  • status: [fp] marks the issues as false positives; [accept] or no status accepts them.
  • rules: comma-separated rule keys with the repository, such as plsql:EmptyBlock.
  • justification: required free text.

SonarQube applies these comments only when issue resolution is enabled, first globally (sonar.issues.issueResolution.global.enabled) and then on the project (sonar.issues.issueResolution.enabled). A malformed comment is ignored with a warning in the analysis log.