Make sure you have set your JAVA_HOME variable and add it to your path.
Click on Windows start button
Search for “advanced system settings”
Click on “View advanced system settings”
Click on “Advanced” tab
Click on “Environment Variables…” button
In the “System variables” section, add JAVA_HOME environment variable with the name as JAVA_HOME and value as the exact path to your JDK installation, e.g. C:\Program Files\Java\jdk1.8.0_60
In the “System variables” section, click on PATH and click on Edit... button
Append %JAVA_HOME%\bin to the end of the line. You can use a ; to separate the previous paths. If you are on Windows 10, just click on “New” button and add %JAVA_HOME%\bin and click on “OK” button.
Lastly, go to command prompt and confirm:
java -version
echo %JAVA_HOME%
There are many examples of this such as shown on mkyong here.
Please provide the entire PATH or a screenshot and let’s check it. Also, please close and reopen your shell application to restart the application, e.g. if you are using git-bash, close all git-bash windows then open a new git-bash shell window and check again.
And I have added sonar-project.properties file in the root directory of angular project with the below code.
Please let me know the sonar.projectKey is nothing but that we need to create a new project in sonarqube and generate a token and the same will be added here? and other added properties are correct?
# must be unique in a given SonarQube instance
sonar.projectKey=my:project
# --- optional properties ---
# defaults to project key
sonar.projectName=Sample Anuglar Project
# defaults to 'not provided'
sonar.projectVersion=1.0
# Path is relative to the sonar-project.properties file. Defaults to .
sonar.sources=.
# Encoding of the source code. Default is default system encoding
sonar.sourceEncoding=UTF-8
And below command lines are there in the sonar-scanner.properties file sonarscanner directory/conf/sonar-scanner.properties.
#Configure here general information about the environment, such as SonarQube server connection details for example
#No information about specific project should appear here
#----- Default SonarQube server
sonar.host.url=http://localhost:9000
#----- Default source code encoding
#sonar.sourceEncoding=UTF-8
Great! You have sonar-scanner running now. Please make sure to read SonarScanner usage docs first.
Now, you need to make sure to add it to your PATH environment variable so you don’t need to type the entire path to sonar-scanner, just like what you did with %JAVA_HOME%\bin earlier, just add a New entry for your path C:\User\...\sonar-scanner-4.4.0.2170\bin. After restarting command shell, you can just type sonar-scanner.bat instead of the full path to sonar-scanner.bat.
Lastly, you have the correct properties in your sonar-project.properties, but I suggest just setting the projectKey and projectName first to test things out. Run sonar-scanner.bat in your Angular code directory and check the SonarQube server at http://localhost:9000, login with the default admin user (admin) and password admin, and check your analysis there.
I have done the first part i.e. adding the new entry “C:\User…\sonar-scanner…\bin” to the Path environment variable.
When I type the sonar-scanner.bat in the angular project directory its showing the below list of lines where the project configuration file is showing as NONE and also let me know how to check the sonarqube server at http://localhost:9000?
INFO: Scanner configuration file: C:\XXXXXX\XXXXX XXXXX\Documents\XXXX\Softwares\sonar-scanner-msbuild-4.10.0.19059-net46\sonar-scanner-4.4.0.2170\bin…\conf\sonar-scanner.properties
INFO: Project root configuration file: NONE
INFO: SonarScanner 4.4.0.2170
INFO: Java 1.8.0_261 Oracle Corporation (32-bit)
INFO: Windows 10 10.0 x86
INFO: User cache: C:\XXXX.sonar\cache
Please respond with all the commands you are typing. You are missing the sonar-project.properties file, which explains why it is missing for the “Project root configuration file” as NONE. Also, make sure you are in the angular project directory. We need all your console output in order to assist, so reply with that information and we can assist.
Also, make sure to read this page once then read it one more time: SonarScanner CLI
Here’s a youtube tutorial video that explains most of the details we have talked about and gives an example, although the SonarQube version is a little bit older, it is same concepts: https://www.youtube.com/watch?v=31igoWxauEQ
I have made one mistake so i have corrected by placing the sonar-project.properties file in the root directory of angular project and ran the code. PFB screenshot.
Then please let me know the next steps. I try to browse the URL http://localhost:9000/ in a browser its keep on loading nothing is happening. Am I doing anything wrong here?
Please find the below console output log when i run the sonar-scanner.bat in the command line of angular project directory.
INFO: EXECUTION FAILURE
INFO: ------------------------------------------------------------------------
INFO: Total time: 5:02.552s
INFO: Final Memory: 4M/15M
INFO: ------------------------------------------------------------------------
ERROR: Error during SonarScanner execution
org.sonarsource.scanner.api.internal.ScannerException: Unable to execute SonarScanner analysis
at org.sonarsource.scanner.api.internal.IsolatedLauncherFactory.lambda$createLauncher$0(IsolatedLauncherFactory.java:85)
at java.security.AccessController.doPrivileged(Native Method)
at org.sonarsource.scanner.api.internal.IsolatedLauncherFactory.createLauncher(IsolatedLauncherFactory.java:74)
at org.sonarsource.scanner.api.internal.IsolatedLauncherFactory.createLauncher(IsolatedLauncherFactory.java:70)
at org.sonarsource.scanner.api.EmbeddedScanner.doStart(EmbeddedScanner.java:185)
at org.sonarsource.scanner.api.EmbeddedScanner.start(EmbeddedScanner.java:123)
at org.sonarsource.scanner.cli.Main.execute(Main.java:73)
at org.sonarsource.scanner.cli.Main.main(Main.java:61)
Caused by: java.lang.IllegalStateException: Fail to get bootstrap index from server
at org.sonarsource.scanner.api.internal.BootstrapIndexDownloader.getIndex(BootstrapIndexDownloader.java:42)
at org.sonarsource.scanner.api.internal.JarDownloader.getScannerEngineFiles(JarDownloader.java:58)
at org.sonarsource.scanner.api.internal.JarDownloader.download(JarDownloader.java:53)
at org.sonarsource.scanner.api.internal.IsolatedLauncherFactory.lambda$createLauncher$0(IsolatedLauncherFactory.java:76)
... 7 more
Caused by: java.net.SocketTimeoutException: Read timed out
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.socketRead(SocketInputStream.java:116)
at java.net.SocketInputStream.read(SocketInputStream.java:171)
at java.net.SocketInputStream.read(SocketInputStream.java:141)
at org.sonarsource.scanner.api.internal.shaded.okio.Okio$2.read(Okio.java:140)
at org.sonarsource.scanner.api.internal.shaded.okio.AsyncTimeout$2.read(AsyncTimeout.java:237)
at org.sonarsource.scanner.api.internal.shaded.okio.RealBufferedSource.read(RealBufferedSource.java:51)
at org.sonarsource.scanner.api.internal.shaded.okhttp.internal.http1.Http1ExchangeCodec$AbstractSource.read(Http1ExchangeCodec.java:389)
at org.sonarsource.scanner.api.internal.shaded.okhttp.internal.http1.Http1ExchangeCodec$UnknownLengthSource.read(Http1ExchangeCodec.java:529)
at org.sonarsource.scanner.api.internal.shaded.okhttp.internal.connection.Exchange$ResponseBodySource.read(Exchange.java:286)
at org.sonarsource.scanner.api.internal.shaded.okio.RealBufferedSource.select(RealBufferedSource.java:100)
at org.sonarsource.scanner.api.internal.shaded.okhttp.internal.Util.bomAwareCharset(Util.java:467)
at org.sonarsource.scanner.api.internal.shaded.okhttp.ResponseBody.string(ResponseBody.java:181)
at org.sonarsource.scanner.api.internal.ServerConnection.downloadString(ServerConnection.java:100)
at org.sonarsource.scanner.api.internal.BootstrapIndexDownloader.getIndex(BootstrapIndexDownloader.java:39)
... 10 more
ERROR:
ERROR: Re-run SonarScanner using the -X switch to enable full debug logging.
We already have Sonarqube hosted in our company server so I can able to access and setup the project i.e. I have created a project key and token in the sonarqube server.
For sonar.host.url, you need to set it to your company’s server, not http://localhost:9000.
For example, if your company’s sonarqube server is https://dev.venkat.com, then you need to set the sonar.host.url=https://dev.venkat.com in your sonar-project.properties file.
Thanks. Now I can able to see the analysis results in the the sonarqube server
I have three things which are pending in order to complete Sonascanner integration end to end.
If you see the above attached screenshot where you can see the java version Java 1.8.0_261 (32 bit). But I have 64 bit machine where I installed the Jdk 14.0.2 64 bit and try to refer the path in the System environment variables. Then when i run the sonar scanner it’s not working because java command is not able to recognize.
Can you please let me know how can we integrate the code coverage with the angular project.
What would be the command to integrate the sonar scanner into Github pipeline?
I suggest making sure you deleted the 32 bit version everywhere, double-check the PATH and environment variable JAVA_HOME, confirm in the terminal that java -version is what you expect, then replace it with 64 bit version, make updates, and check again. You might want to restart your computer since you’ve made so many changes.
I just realized that we do not support Java 14 for the SonarScanner, see Prerequisites and Overview, if you are using the SonarQube 8.5 (latest version as of today).
I have un-installed the Java 8 from my machine and now only contains Jdk 14.0.2 (64 bit) under the programs files folder where i can see the Java folder.
Then open the command prompt to check the java version. PFA what it’s showing.