Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  • The source directory should be set to the directory containing the top parent package. For example, if your directory structure is 'src/main/java/com/mycompany/...', the source directory must be set to 'src/main/java'.
  • The source directory tree has to match the package declaration. For example, the following class:

 

Code Block
titleMyClass.java
linenumberstrue
languagejava
package com.mycompany.mypackage;
...

 must be located in the following directory: [mySourceDirectory]/com/mycompany/mypackage/MyClass.java. Otherwise you would get such an error while running your analysis:

 

Code Block
titleLog
languagenone
Exception in thread "main" org.sonar.batch.bootstrapper.BootstrapException: org.sonar.squid.api.AnalysisException: Got an exception - org.sonar.squid.api.AnalysisException: The source directory does not correspond to the package declaration com.mycompany.mypackage, file : ..\src\MyClass.java
...

Tests and Code Coverage

The default code coverage engine for unit tests can be set in Settings > Configuration > General Settings > Java > Code coverage plugin property.

By default the code coverage engine is JaCoCo but CoberturaEmma or Clover can also be used.

To deal with unit tests and code coverage for Java project in Sonar, see Code Coverage by Unit Tests for Java Project tutorial.

To deal with integration tests and code coverage for Java project in Sonar, see Code Coverage by Integration Tests for Java Project tutorial.

Advanced Settings

Documentation on advanced parameters is available on the Analysis Parameters page.

Advanced parameters specific to Java are:

KeyDescriptionDefault value

sonar.skipDesign

Deactivate Java bytecode analysis. The Java bytecode is analyzed by Sonar in order to extract dependencies between packages and files. These dependencies are used for instance to display the DSM (Dependency System Matrix). This bytecode analysis can be deactivated.

false

sonar.java.source

Java version of the source code. This property is not used by the Sonar core but can be used by Java Sonar plugin like the PMD plugin. 

1.5

FAQ

See Java Ecosystem FAQ.

Metrics

See Metrics documentation page.

Android

A sample project with code coverage computed with Emma is available on GitHub that can be browsed or downloaded: /projects/android

Extending Coding Rules using XPath

New coding rules can be added using XPath. See the related documentation.

To navigate the AST, download the SSLR Java Toolkit.

Change Log

JIRA Issues
anonymoustrue
titleRelease 1.1
renderModestatic
width900
columnstype;key;summary;priority
urlhttp://jira.codehaus.org/sr/jira.issueviews:searchrequest-xml/temp/SearchRequest.xml?fixfor=18937&pid=12830&sorter/field=priority&sorter/order=DESC&tempMax=1000