You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

sonarscanner.md 5.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. ---
  2. title: SonarScanner
  3. url: /analysis/scan/sonarscanner/
  4. ---
  5. [[info]]
  6. | **Download SonarScanner 4.0** - Compatible with SonarQube 6.7+ (LTS) and SonarCloud
  7. | By [SonarSource](https://www.sonarsource.com/) – GNU LGPL 3 – [Issue Tracker](https://jira.sonarsource.com/browse/SQSCANNER) – [Source](https://github.com/Sonarsource/sonar-scanner-cli)
  8. |
  9. | [Linux 64-bit](https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-4.0.0.1744-linux.zip) |
  10. | [Windowx 64-bit](https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-4.0.0.1744-windows.zip) |
  11. | [Mac OS X 64-bit](https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-4.0.0.1744-macosx.zip) |
  12. | [Any*](https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-4.0.0.1744.zip)
  13. | *Requires a pre-installed JVM - with the same requirements as the SonarQube server.
  14. The SonarScanner is the scanner to use when there is no specific scanner for your build system.
  15. ## Installation
  16. * Expand the downloaded file into the directory of your choice. We'll refer to it as `$install_directory` in the next steps.
  17. * Update the global settings to point to your SonarQube server by editing `$install_directory/conf/sonar-scanner.properties`:
  18. ```
  19. #----- Default SonarQube server
  20. #sonar.host.url=http://localhost:9000
  21. ```
  22. * Add the `$install_directory/bin` directory to your path.
  23. * Verify your installation by opening a new shell and executing the command `sonar-scanner -h` (`sonar-scanner.bat -h` on Windows). You should get output like this:
  24. ```
  25. usage: sonar-scanner [options]
  26. Options:
  27. -D,--define <arg> Define property
  28. -h,--help Display help information
  29. -v,--version Display version information
  30. -X,--debug Produce execution debug output
  31. ```
  32. If you need more debug information you can add one of the following to your command line: `-X`, `--verbose`, or `-Dsonar.verbose=true`.
  33. ## Use
  34. Create a configuration file in the root directory of the project: `sonar-project.properties`
  35. ```
  36. sonar-project.properties
  37. # must be unique in a given SonarQube instance
  38. sonar.projectKey=my:project
  39. # --- optional properties ---
  40. # defaults to project key
  41. #sonar.projectName=My project
  42. # defaults to 'not provided'
  43. #sonar.projectVersion=1.0
  44. # Path is relative to the sonar-project.properties file. Defaults to .
  45. #sonar.sources=.
  46. # Encoding of the source code. Default is default system encoding
  47. #sonar.sourceEncoding=UTF-8
  48. ```
  49. Run the following command from the project base directory to launch the analysis:
  50. `sonar-scanner`
  51. ## Sample Projects
  52. To help you get started, simple project samples are available for most languages on github. They can be [browsed](https://github.com/SonarSource/sonar-scanning-examples) or [downloaded](https://github.com/SonarSource/sonar-scanning-examples/archive/master.zip). You'll find them filed under sonarqube-scanner/src.
  53. ## Alternatives to sonar-project.properties
  54. If a sonar-project.properties file cannot be created in the root directory of the project, there are several alternatives:
  55. * The properties can be specified directly through the command line. Ex:
  56. ```
  57. sonar-scanner -Dsonar.projectKey=myproject -Dsonar.sources=src1
  58. ```
  59. * The property project.settings can be used to specify the path to the project configuration file (this option is incompatible with the `sonar.projectBaseDir` property). Ex:
  60. ```
  61. sonar-scanner -Dproject.settings=../myproject.properties
  62. ```
  63. * The root folder of the project to analyze can be set through the `sonar.projectBaseDir` property since SonarScanner 2.4. This folder must contain a `sonar-project.properties` file if `sonar.projectKey` is not specified on the command line.
  64. Additional analysis parameters can be defined in this project configuration file or through command-line parameters.
  65. ## Alternate Analysis Directory
  66. If the files to be analyzed are not in the directory where the analysis starts from, use the `sonar.projectBaseDir` property to move analysis to a different directory. E.G. analysis begins from `jenkins/jobs/myjob/workspace` but the files to be analyzed are in `ftpdrop/cobol/project1`.
  67. ```
  68. sonar-project.properties
  69. sonar.projectBaseDir=/home/ftpdrop/cobol/project1
  70. sonar.sources=src
  71. sonar.cobol.copy.directories=/copy
  72. For more, see the listing of analysis parameters.
  73. ```
  74. ## Troubleshooting
  75. **Java heap space error or java.lang.OutOfMemoryError**
  76. Increase the memory via the `SONAR_SCANNER_OPTS` environment variable:
  77. ```
  78. export SONAR_SCANNER_OPTS="-Xmx512m"
  79. ```
  80. On Windows environments, avoid the double-quotes, since they get misinterpreted and combine the two parameters into a single one.
  81. ```
  82. set SONAR_SCANNER_OPTS=-Xmx512m
  83. ```
  84. **Unsupported major.minor version**
  85. Upgrade the version of Java being used for analysis or use one of the native package (that embed its own Java runtime).
  86. **Property missing: `sonar.cs.analyzer.projectOutPaths'. No protobuf files will be loaded for this project.**
  87. Scanner CLI is not able to analyze .NET projects. Please, use Scanner for MSBuild. If you are running Scanner for MSBuild, ensure that you are not hitting a known limitation.