Quick Search
Browse
Pages
Blog
Labels
Attachments
Mail
Advanced
What’s New
Space Directory
Feed Builder
Keyboard Shortcuts
Confluence Gadgets
Log In
Sign Up
Dashboard
Sonar
Copy Page
You are not logged in. Any changes you make will be marked as
anonymous
. You may want to
Log In
if you already have an account. You can also
Sign Up
for a new account.
This page is being edited by
.
Paragraph
Paragraph
Heading 1
Heading 2
Heading 3
Heading 4
Heading 5
Heading 6
Preformatted
Quote
Bold
Italic
Underline
More colours
Strikethrough
Subscript
Superscript
Monospace
Clear Formatting
Bullet list
Numbered list
Outdent
Indent
Align left
Align center
Align right
Link
Table
Insert
Insert Content
Image
Link
Attachment
Symbol
Emoticon
Wiki Markup
Horizontal rule
tinymce.confluence.insert_menu.macro_desc
Info
JIRA Issue
Status
Gallery
Tasklist
Table of Contents
Other Macros
Page Layout
No Layout
Two column (simple)
Two column (simple, left sidebar)
Two column (simple, right sidebar)
Three column (simple)
Two column
Two column (left sidebar)
Two column (right sidebar)
Three column
Three column (left and right sidebars)
Undo
Redo
Find/Replace
Keyboard Shortcuts Help
<table class="wysiwyg-macro" data-macro-name="info" data-macro-parameters="icon=false|title=Table of Contents" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2luZm86aWNvbj1mYWxzZXx0aXRsZT1UYWJsZSBvZiBDb250ZW50c30&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="RICH_TEXT"><tr><td class="wysiwyg-macro-body"><p><img class="editor-inline-macro" src="/plugins/servlet/confluence/placeholder/macro?definition=e3RvYzptYXhMZXZlbD0yfQ&locale=en_GB&version=2" data-macro-name="toc" data-macro-parameters="maxLevel=2"></p></td></tr></table><p>The Sonar Runner is recommended as the default launcher to analyze a project with Sonar.</p><h1>Prerequisites</h1><p>You must have previously <a class="confluence-link" href="/display/SONAR/Installing+and+Configuring+Sonar+Runner" data-linked-resource-id="229737015" data-linked-resource-type="page" data-linked-resource-default-alias="Installing and Configuring Sonar Runner" data-base-url="http://docs.codehaus.org">installed the Sonar Runner</a> and read <a class="confluence-link" href="/display/SONAR/Analyzing+Source+Code" data-linked-resource-id="113541695" data-linked-resource-type="page" data-linked-resource-default-alias="Analyzing Source Code" data-base-url="http://docs.codehaus.org">Analyzing Code Source</a>.</p><table class="wysiwyg-macro" data-macro-name="note" data-macro-parameters="title=Sonar Runner 2.0+" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e25vdGU6dGl0bGU9U29uYXIgUnVubmVyIDIuMCt9&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="RICH_TEXT"><tr><td class="wysiwyg-macro-body"><p>This page describes how to use the Sonar Runner 2.0+</p></td></tr></table><h1>Usage</h1><h2>Simple Project</h2><p>Create a configuration file in the root directory of the project: sonar-project.properties</p><table class="wysiwyg-macro" data-macro-name="code" data-macro-parameters="language=bash|title=sonar-project.properties" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGU6dGl0bGU9c29uYXItcHJvamVjdC5wcm9wZXJ0aWVzfGxhbmd1YWdlPWJhc2h9&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre># required metadata sonar.projectKey=my:project sonar.projectName=My project sonar.projectVersion=1.0 # optional description sonar.projectDescription=Fake description # path to source directories (required) sonar.sources=srcDir1,srcDir2 # path to test source directories (optional) sonar.tests=testDir1,testDir2 # path to project binaries (optional), for example directory of Java bytecode sonar.binaries=binDir # optional comma-separated list of paths to libraries. Only path to JAR file is supported. sonar.libraries=path/to/library/*.jar,path/to/specific/library/myLibrary.jar,parent/*/*.jar # The value of the property must be the key of the language. sonar.language=cobol # Additional parameters sonar.my.property=value </pre></td></tr></table><p>Run the following command from the project base directory to launch the Sonar analysis:</p><table class="wysiwyg-macro" data-macro-name="code" data-macro-parameters="language=none" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGU6bGFuZ3VhZ2U9bm9uZX0&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre>sonar-runner</pre></td></tr></table><h3>Security</h3><p>Since Sonar 3.4, if a project cannot be accessed anonymously, the 'sonar.login' and 'sonar.password' properties are required to run an analysis on this project. These properties have to be set to the credentials of a user having the 'User' role on this project. You can set them either:</p><ul><li>directly on the command line by adding -Dsonar.login=myUser -Dsonar.password=myPassword</li><li>or in the 'sonar-project.properties' project configuration file</li><li>or in the 'sonar-runner.properties' global configuration file</li></ul><p>A project cannot be anonymously accessed when either:</p><ul><li>the '<a class="confluence-link" href="/display/SONAR/Security" data-linked-resource-id="135200868" data-linked-resource-type="page" data-linked-resource-default-alias="Security" data-base-url="http://docs.codehaus.org">sonar.forceAuthentication</a>' property is set to 'true'</li><li>or the '<a class="confluence-link" href="/display/SONAR/Security" data-linked-resource-id="135200868" data-linked-resource-type="page" data-linked-resource-default-alias="Security" data-base-url="http://docs.codehaus.org">sonar.forceAuthentication</a>' property is set to 'false' and the 'Anyone' group has not been granted a 'User' role on the project</li></ul><h3>Project Samples</h3><p>To help you getting started, for each language, a simple project sample is available on github that can be <a class="external-link" href="https://github.com/SonarSource/sonar-examples" rel="nofollow">browsed</a> or <a class="external-link" href="https://github.com/SonarSource/sonar-examples/zipball/master" rel="nofollow">downloaded</a>: projects/languages</p><h2>Multi-module Project</h2><p>There are two ways to define a multi-module structure in Sonar:</p><table class="confluenceTable"><tbody><tr><th class="confluenceTh"> </th><th colspan="1" class="confluenceTh">Using the given file structure...</th><th class="confluenceTh">... with the given 'properties' files</th></tr><tr><td class="confluenceTd"><p><u><strong>Way #1</strong></u></p><p><strong>Set all the configuration in the properties file in the root folder</strong></p></td><td colspan="1" class="confluenceTd"><img class="confluence-embedded-image" src="/download/attachments/231080045/Props-All-On-Root.jpg?version=1&modificationDate=1369273822500" data-image-src="/download/attachments/231080045/Props-All-On-Root.jpg?version=1&modificationDate=1369273822500" data-linked-resource-id="231375388" data-linked-resource-type="attachment" data-linked-resource-default-alias="Props-All-On-Root.jpg" data-base-url="http://docs.codehaus.org" data-linked-resource-container-id="231080045" title="null > Props-All-On-Root.jpg"></td><td class="confluenceTd"><table class="wysiwyg-macro" data-macro-name="code" data-macro-parameters="language=bash|linenumbers=true|title="MyProject/sonar-project.properties" file content" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGU6dGl0bGU9Ik15UHJvamVjdC9zb25hci1wcm9qZWN0LnByb3BlcnRpZXMiIGZpbGUgY29udGVudHxsaW5lbnVtYmVycz10cnVlfGxhbmd1YWdlPWJhc2h9&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre># Root project information sonar.projectKey=org.mycompany.myproject sonar.projectName=My Project sonar.projectVersion=1.0-SNAPSHOT # Some properties that will be inherited by the modules sonar.sources=src # List of the module identifiers sonar.modules=module1,module2 # Properties can obviously be overriden for # each module - just prefix them with the module ID module1.sonar.projectName=Module 1 module2.sonar.projectName=Module 2 </pre></td></tr></table></td></tr><tr><td class="confluenceTd"><p><u><strong>Way #2</strong></u></p><p><strong>Set the configuration in multiple properties files</strong></p></td><td colspan="1" class="confluenceTd"><img class="confluence-embedded-image" src="/download/attachments/231080045/Props-On-Modules.jpg?version=1&modificationDate=1369273822482" data-image-src="/download/attachments/231080045/Props-On-Modules.jpg?version=1&modificationDate=1369273822482" data-linked-resource-id="231375387" data-linked-resource-type="attachment" data-linked-resource-default-alias="Props-On-Modules.jpg" data-base-url="http://docs.codehaus.org" data-linked-resource-container-id="231080045" title="null > Props-On-Modules.jpg"></td><td class="confluenceTd"><table class="wysiwyg-macro" data-macro-name="code" data-macro-parameters="language=bash|linenumbers=true|title="MyProject/sonar-project.properties" file content" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGU6dGl0bGU9Ik15UHJvamVjdC9zb25hci1wcm9qZWN0LnByb3BlcnRpZXMiIGZpbGUgY29udGVudHxsaW5lbnVtYmVycz10cnVlfGxhbmd1YWdlPWJhc2h9&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre># Root project information sonar.projectKey=org.mycompany.myproject sonar.projectName=My Project sonar.projectVersion=1.0-SNAPSHOT # Some properties that will be inherited by the modules sonar.sources=src # List of the module identifiers sonar.modules=module1,module2</pre></td></tr></table><table class="wysiwyg-macro" data-macro-name="code" data-macro-parameters="language=bash|linenumbers=true|title="MyProject/module1/sonar-project.properties" file content" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGU6dGl0bGU9Ik15UHJvamVjdC9tb2R1bGUxL3NvbmFyLXByb2plY3QucHJvcGVydGllcyIgZmlsZSBjb250ZW50fGxpbmVudW1iZXJzPXRydWV8bGFuZ3VhZ2U9YmFzaH0&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre># Redefine properties # Note that you do not need to prefix the property here sonar.projectName=Module 1</pre></td></tr></table><table class="wysiwyg-macro" data-macro-name="code" data-macro-parameters="language=bash|linenumbers=true|title="MyProject/module2/sonar-project.properties" file content" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGU6dGl0bGU9Ik15UHJvamVjdC9tb2R1bGUyL3NvbmFyLXByb2plY3QucHJvcGVydGllcyIgZmlsZSBjb250ZW50fGxpbmVudW1iZXJzPXRydWV8bGFuZ3VhZ2U9YmFzaH0&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre># Redefine properties # Note that you do not need to prefix the property here sonar.projectName=Module 2</pre></td></tr></table></td></tr></tbody></table><p> </p><p><u><strong>Noteworthy</strong></u>:</p><ul><li><strong>Properties are inherited from parent to children</strong> <br />They can obviously be overriden:<br /><ul><li>By prefixing them with the module identifier (way #1)</li><li>Simply by defining them in the 'sonar-project.properties' file located in the module (way #2)<br /><br /></li></ul></li><li><strong>Module base directory can be specified for special cases</strong><br />By default, the module base directory is guessed from the module identifier (like in the examples above). But it can be redefined using the 'sonar.projectBaseDir' property.<br />For instance, here are two use cases and the way to redefine the base directory of the modules:<br /><ul><li><p>the folder of a module contains white spaces or special characters:</p><table class="wysiwyg-macro" data-macro-name="code" data-macro-parameters="language=bash" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGU6bGFuZ3VhZ2U9YmFzaH0&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre>module1.sonar.projectBaseDir=My Module One</pre></td></tr></table><p> </p></li><li><p>the module is not located directly in the parent folder, but in a deeper directory structure:</p><table class="wysiwyg-macro" data-macro-name="code" data-macro-parameters="language=bash" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGU6bGFuZ3VhZ2U9YmFzaH0&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre>module1.sonar.projectBaseDir=modules/mod1 module2.sonar.projectBaseDir=modules/mod2</pre></td></tr></table><p> </p></li></ul></li></ul><div><ul><li>A project that defines modules (or a module that defines sub-modules) cannot define a source code folder to be analyzed by Sonar.<br /> </li></ul></div><p>To help you getting started, multi-module project samples are available on github that can be <a class="external-link" href="https://github.com/SonarSource/sonar-examples" rel="nofollow">browsed</a> or <a class="external-link" href="https://github.com/SonarSource/sonar-examples/zipball/master" rel="nofollow">downloaded</a>:</p><ul><li>Modules with the same structure: projects/multi-module/sonar-runner/java-sonar-runner-modules-same-structure<a class="js-slide-to js-rewrite-sha" href="https://github.com/SonarSource/sonar-examples/tree/master/projects/languages/java/sonar-runner/java-sonar-runner-modules-same-structure" /></li><li>Modules with different structures: projects/multi-module/sonar-runner/java-sonar-runner-modules-different-structures</li><li>A configuration file for each module: projects/multi-module/sonar-runner/java-sonar-runner-modules-own-configuration-file<a class="js-slide-to js-rewrite-sha" href="https://github.com/SonarSource/sonar-examples/tree/master/projects/languages/java/sonar-runner/java-sonar-runner-modules-own-configuration-file" /></li></ul><h2>Multi-module and Multi-language Project</h2><p>Since Sonar 3.3, it is possible to run an analysis on a multi-module project whose modules contains source code from different languages.</p><p>In addition to the <a class="confluence-link" href="#Multi-module Project" data-anchor="Multi-module Project" data-linked-resource-default-alias="Multi-module Project" data-base-url="http://docs.codehaus.org">multi-module configuration</a>, the only mandatory property to set is the language for each module:</p><table class="wysiwyg-macro" data-macro-name="code" data-macro-parameters="language=bash|linenumbers=true|title=module.sonar.language" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGU6dGl0bGU9bW9kdWxlLnNvbmFyLmxhbmd1YWdlfGxpbmVudW1iZXJzPXRydWV8bGFuZ3VhZ2U9YmFzaH0&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre>module1.sonar.language=java module2.sonar.language=javascript ...</pre></td></tr></table><p>To help you getting started, a multi-language project sample is available on github that can be <a class="external-link" href="https://github.com/SonarSource/sonar-examples" rel="nofollow">browsed</a> or <a class="external-link" href="https://github.com/SonarSource/sonar-examples/zipball/master" rel="nofollow">downloaded</a>: projects/languages/multi-language/multi-language-java-javascript-sonar-runner</p><h2>Advanced Usage</h2><p>If a sonar-project.properties file cannot be created in the root directory of the project, there are several alternatives:</p><ul><li><p>The properties can be specified directly through the command line. Ex:</p><table class="wysiwyg-macro" data-macro-name="code" data-macro-parameters="language=none" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGU6bGFuZ3VhZ2U9bm9uZX0&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre>sonar-runner -Dsonar.projectKey=myproject -Dsonar.sources=src1</pre></td></tr></table><p> </p></li><li><p>The property 'project.settings' can be used to specify the path to the project configuration file (this option is incompatible with the 'project.home' property). Ex:</p><table class="wysiwyg-macro" data-macro-name="code" data-macro-parameters="language=none" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGU6bGFuZ3VhZ2U9bm9uZX0&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre>sonar-runner -Dproject.settings=../myproject.properties</pre></td></tr></table><p> </p></li></ul><p>The root folder of the project to analyze can be set through the 'project.home' property. This folder must contain a sonar-project.properties file if the mandatory properties (like 'sonar.projectKey') are not specified on the command line.</p><p><a class="confluence-link" href="/display/SONAR/Analysis+Parameters" data-linked-resource-id="113541435" data-linked-resource-type="page" data-linked-resource-default-alias="Analysis Parameters" data-base-url="http://docs.codehaus.org">Additional analysis parameters</a> can be defined in this project configuration file or through command-line parameters. </p><h1>Troubleshootings</h1><table class="wysiwyg-macro" data-macro-name="note" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e25vdGV9&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="RICH_TEXT"><tr><td class="wysiwyg-macro-body"><p>If you get an java.lang.OutOfMemoryError, you can set the SONAR_RUNNER_OPTS environment variable, like this in *nix environments:</p><table class="wysiwyg-macro" data-macro-name="code" data-macro-parameters="language=none" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGU6bGFuZ3VhZ2U9bm9uZX0&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre>export SONAR_RUNNER_OPTS="-Xmx512m -XX:MaxPermSize=128m" </pre></td></tr></table><p>On Windows environments, avoid the double-quotes, since they get misinterpreted, turning the two parameters into a single one.</p><table class="wysiwyg-macro" data-macro-name="code" data-macro-parameters="language=none" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGU6bGFuZ3VhZ2U9bm9uZX0&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre>set SONAR_RUNNER_OPTS=-Xmx512m -XX:MaxPermSize=128m </pre></td></tr></table></td></tr></table><h1>Migrating from Sonar Runner 1.X to Sonar Runner 2.0</h1><p>Replace the following properties in the sonar-project.properties file:</p><ul><li>sources => sonar.sources</li><li>tests => sonar.tests</li><li>binaries => sonar.binaries</li><li>libraries => sonar.libraries</li></ul><div>Explicitly set the sonar.sourceEncoding property in the sonar-project.properties file.</div>
Please type the word appearing in the picture.
Attachments
Labels
Location
Watch this page
< Edit
Preview >
Loading…
Save
Cancel
Next hint
search
attachments
weblink
advanced