Scanning a Project
This tutorial will demonstrate how to scan a project using the nx-sonarqube Nx Plugin and upload the results to Sonar
Prerequisites
- Nx workspace
- nx-sonarqube
- @nx/jest or @nx/vite test executors with code coverage enabled
- Sonar
Steps
-
Given the existing project to be scanned is named
app
, run the following generator: -
The generator will create the following changes:
-
The
sonar
target is added: -
The
sonar
andtest
targets are added so thattest
will depend on the project dependencies’ tests:
-
-
Sonar can require authentication credentials. You can set these via environment variables using the Define Environment Variables Recipe
- SONAR_LOGIN: The authentication token or login of a SonarQube user with either Execute Analysis permission on the project or Global Execute Analysis permission
- SONAR_PASSWORD: If you’re using an authentication token, leave this blank. If you’re using a login, this is the password that goes with your SONAR_LOGIN username
-
Execute the
sonar
task against theapp
project: -
The executor will output the following to the terminal where the status of scan can be checked:
-
Click the link in the terminal out & log into Sonar to view the results: