When execute command: lcov --capture --directory . --no-external --output-file coverage.info to generate code coverage report, I encountered the following error:
$ lcov --capture --directory . --no-external --output-file coverage.info Capturing coverage data from . Can't locate JSON/PP.pm in @INC (@INC contains: /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .) at /usr/local/bin/geninfo line 63. BEGIN failed--compilation aborted at /usr/local/bin/geninfo line 63. sh-4.2$ perl -MCPAN -e 'install JSON' Can't locate CPAN.pm in @INC (@INC contains: /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .). BEGIN failed--compilation aborted.
In my opinion, SonarQube is not a very easy setup DevOps tool to compare with Jenkins, Artifactory. You can’t just run some script under the bin folder to let the server boot up.
You must have an installed database, configuration LDAP in the config file, etc.
So I’d like to document some important steps for myself, like setup LDAP or PostgreSQL when I install SonarQube of v9.0.1. It would be better if it can help others.
Prerequisite and Download
Need to be installed JRE/JDK 11 on the running machine.
cd sonarqube/ ls wget https://binaries.sonarsource.com/Distribution/sonarqube/sonarqube-9.0.1.46107.zip
unzip sonarqube-9.0.1.46107.zip cd sonarqube-9.0.1.46107/bin/linux-x86-64 sh sonar.sh console
Change Java version
I installed SonarQube on CentOS 7 machine, the Java version is OpenJDK 1.8.0_242 by default, but the prerequisite shows at least need JDK 11. There is also JDK 11 available on my machine, so I just need to change the Java version.
I recommend using the alternatives command change Java version,refer as following:
$ java -version openjdk version "1.8.0_242" OpenJDK Runtime Environment (build 1.8.0_242-b08) OpenJDK 64-Bit Server VM (build 25.242-b08, mixed mode)
Enter to keep the current selection[+], or type selection number: 3 $ java -version openjdk version "11.0.12" 2021-07-20 LTS OpenJDK Runtime Environment 18.9 (build 11.0.12+7-LTS) OpenJDK 64-Bit Server VM 18.9 (build 11.0.12+7-LTS, mixed mode, sharing)
Install Database
SonarQube needs you to have installed a database. It supports several database engines, like Microsoft SQL Server, Oracle, and PostgreSQL. Since PostgreSQL is open source, light, and easy to install, so I choose PostgreSQL as its database.
4. How to fix ‘Could not resolve 11 file paths in lcov.info’
I want to display Javascript code coverage result in SonarQube, so I added sonar.javascript.lcov.reportPaths=coverage/lcov.info to the sonar-project.properties
But when I run sonar-scanner.bat in the command line, the code coverage result can not show in sonar. I noticed the following error from the output:
INFO: Analysing [C:\workspace\xvm-ide\client\coverage\lcov.info] WARN: Could not resolve 11 file paths in [C:\workspace\xvm-ide\client\coverage\lcov.info]