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
SonarQube
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>This analyzer is recommended to launch analysis on Java Maven project.</p><h1>Prerequisites</h1><p>You must have previously <a class="confluence-link" href="/display/SONAR/Installing+and+Configuring+Maven" data-linked-resource-id="229737017" data-linked-resource-type="page" data-linked-resource-default-alias="Installing and Configuring Maven" data-base-url="http://docs.codehaus.org">installed and configured Maven for SonarQube</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><h1>Analyzing a Maven Project</h1><p>Analyzing a Maven project consists of running a Maven goal in the directory where the pom.xml file sits. If possible, an <code>install</code> goal should be performed prior to the <code>sonar:sonar </code>one.</p><h2>Recommended Way</h2><table class="wysiwyg-macro" data-macro-name="code" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGV9&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre>mvn clean install -DskipTests=true mvn sonar:sonar </pre></td></tr></table><p><code>skipTests=true</code> not to run unit tests twice: during the <code>install</code> goal and again during the <code>sonar:sonar</code> goal. You can also deactivate the integration tests execution. Please refer to the Maven documentation.</p><p> </p><table class="wysiwyg-macro" data-macro-name="note" data-macro-parameters="title=Using Eclipse" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e25vdGU6dGl0bGU9VXNpbmcgRWNsaXBzZX0&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="RICH_TEXT"><tr><td class="wysiwyg-macro-body"><p>Make sure you're not using the Eclipse plugin maven embedder. Define a new Maven runtime pointing to your local Maven install, use the latest maven eclipse plugin and uncheck "resolve workspace artifacts" in the maven project launch window.<br />Have a look at the first comment of this ticket: <a href="http://jira.codehaus.org/browse/SONAR-929">http://jira.codehaus.org/browse/SONAR-929</a></p></td></tr></table><table class="wysiwyg-macro" data-macro-name="note" data-macro-parameters="title=Advanced Reactor Options" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e25vdGU6dGl0bGU9QWR2YW5jZWQgUmVhY3RvciBPcHRpb25zfQ&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="RICH_TEXT"><tr><td class="wysiwyg-macro-body"><p>Note that <a href="http://www.sonatype.com/books/mvnref-book/reference/_using_advanced_reactor_options.html">Advanced Reactor Options</a> (such as "--projects" and "--resume-from") are not supported by SonarQube and should not be used.</p></td></tr></table><h2>Alternative Way</h2><p>When the above configuration is not possible, you can run an analysis in one command, but unit tests will run twice: once in the <code>install</code> goal and once in the <code>sonar:</code>sonar one. Do not use the <code><span style="color: rgb(34,34,34);">DskipTests=true</span></code> parameter, otherwise the unit tests will be executed at all.</p><table class="wysiwyg-macro" data-macro-name="code" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGV9&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre>mvn clean install sonar:sonar -Dmaven.test.failure.ignore=true </pre></td></tr></table><p>The <code>-Dmaven.test.failure.ignore=true</code> is there to make sure that even if some unit tests fail, the SonarQube analysis will be performed.</p><h2>Configuring the SonarQubeAnalysis</h2><p>A pom.xml file sample is available <a href="https://github.com/SonarSource/sonar-examples/blob/master/projects/languages/java/maven/java-maven-simple/pom.xml">here</a>.</p><p>Additional analysis parameters are listed on the <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">Analysis Parameters page</a>.</p><h3>Security</h3><p>Since SonarQube 3.4, if a project cannot be accessed anonymously, the <code>sonar.login</code> and <code>sonar.password</code> properties are required to run an analysis on this project. These properties have to be set to the credentials of a user having the <em>User</em> role on this project. You can set them either:</p><ul><li>directly on the command line by adding <code>-Dsonar.login=myUser -Dsonar.password=myPassword</code></li><li>or in the <em>pom.xml</em> file</li><li>or in the Maven profile (<em>settings.xml</em> file)</li></ul><div><p>A project cannot be anonymously accessed when either:</p><ul><li>the <code><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></code> property is set to true</li><li>or the <code><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></code> property is set to 'false' and the <em>Anyone</em> group has not been granted a <em>User</em> role on the project</li></ul></div><div><h3>Sample Projects</h3><p>To help you getting started, 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>: <em>projects/languages/java/maven/java-maven-simple</em></p></div><h2>How to Fix Version of Maven Plugin</h2><p>It is recommended to <a href="http://www.sonatype.com/people/2008/04/maven-209-released/">lock down versions of Maven plugins</a>. Two versions of the Sonar maven plugin exist, one for Maven 2 and one for Maven 3. Fixing its version depends on the Maven versions used to analyse the project:</p><h3>Project analyzed with Maven 2 only</h3><p>Add the following code to the pom.xml file:</p><table class="wysiwyg-macro" data-macro-name="noformat" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e25vZm9ybWF0fQ&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre><build> <pluginManagement> <plugins> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>sonar-maven-plugin</artifactId> <version>1.0</version> </plugin> <plugins> </pluginManagement> </build> </pre></td></tr></table><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>The version 1.0-beta-1 is not supported anymore.</p></td></tr></table><h3>Project analyzed with Maven 3 only</h3><table class="wysiwyg-macro" data-macro-name="noformat" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e25vZm9ybWF0fQ&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre><build> <pluginManagement> <plugins> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>sonar-maven-plugin</artifactId> <version>2.0</version> </plugin> <plugins> </pluginManagement> </build> </pre></td></tr></table><h3>Project analyzed with both Maven 2 and Maven 3</h3><table class="wysiwyg-macro" data-macro-name="noformat" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e25vZm9ybWF0fQ&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre><build> <pluginManagement> <plugins> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>sonar-maven-plugin</artifactId> <version>${sonarVersion}</version> </plugin> <plugins> </pluginManagement> </build> <profile> <id>maven-2</id> <activation> <file> <!-- basedir expression is only recognized by Maven 3.x (see MNG-2363) --> <missing>${basedir}</missing> </file> </activation> <properties> <sonarVersion>1.0</sonarVersion> </properties> </profile> <profile> <id>maven-3</id> <activation> <file> <!-- basedir expression is only recognized by Maven 3.x (see MNG-2363) --> <exists>${basedir}</exists> </file> </activation> <properties> <sonarVersion>2.0</sonarVersion> </properties> </profile> </pre></td></tr></table><h2>Analyzing a Multi-module and Multi-language Project</h2><p>Since SonarQube 3.3, it is possible to run an analysis on a multi-module project whose modules contains source code from different languages.</p><p>To do so, just add the <code>sonar.language</code> property to the pom of each module.</p><p>To help you get 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>: <em>projects/languages/multi-language/multi-language-java-javascript-maven</em></p>
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