To run sonar report, first we have to install maven & sonar in our local machine.For Non maven based project also we require maven because sonar require maven.
- Download and extract Maven in your C drive from http://www.apache.org/dyn/closer.cgi/maven/binaries/apache-maven-3.0.4-bin.zip
- Install Jdk
- Download and extract Sonar in your D drive from http://dist.sonar.codehaus.org/sonar-3.0.zip
- Now go to D:\sonar-3.0\bin\windows-x86-32 and double click on StartSonar.batNow sonar server will start locally on http://localhost:9000
- Here maven require pom.xml for the project for which sonar report is to be generated, but non maven based project will not have any pom.xml.
but we have to create a pom.xml in its project's parent folder as below. <
modelVersion
>4.0.0</
modelVersion
>
<
groupId
>[YOUR.ORGANIZATION]</
groupId
>
<
artifactId
>[YOUR.PROJECT]</
artifactId
>
<
name
>[YOUR PROJECT NAME]</
name
>
<
version
>[YOUR PROJECT VERSION]</
version
>
<
build
>
<
sourceDirectory
>[YOUR SOURCE DIRECTORY]</
sourceDirectory
>
<
outputDirectory
>[YOUR CLASSES/BIN DIRECTORY</
outputDirectory
>
<
plugins
>
<
plugin
>
<
groupId
>org.apache.maven.plugins</
groupId
>
<
artifactId
>maven-compiler-plugin</
artifactId
>
<
configuration
>
<
source
>1.5</
source
>
<
target
>1.5</
target
>
<
excludes
>
<
exclude
>**/*.*</
exclude
>
</
excludes
>
</
configuration
>
</
plugin
>
</
plugins
>
</
build
>
<
properties
>
<
sonar.dynamicAnalysis
>false</
sonar.dynamicAnalysis
>
</
properties
>
</
project
>
- Replace the parameters :
Description Example [YOUR.ORGANIZATION] the id of your organization (no space) com.myorganization [YOUR.PROJECT] the id of your project (no space) my.project [YOUR PROJECT NAME] the name displayed into sonar (spaces allowed) My Project [YOUR PROJECT VERSION] the version. Set 1.0 if no specific version. 1.0 [YOUR SOURCE DIRECTORY] the relative path to the sources directory src/java [YOUR CLASSES/BIN DIRECTORY] the relative path to the compiled java classes directory bin
Go to parent folder of your project, and run following command
mvn sonar:sonar- After its completion, browse http://localhost:9000/ where you will see the project list with code quality report as below
Following the above I created the pom.xml and it worked very well. Thanks. However I get these warnings:
ReplyDelete=====================
[WARNING]
[WARNING] Some problems were encountered while building the effective model for indience:unvired_kernel_android:jar:2
[WARNING] 'build.plugins.plugin.version' for org.apache.maven.plugins:maven-compiler-plugin is missing. @ line 13, column 20
[WARNING]
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING]
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[WARNING]
---------------------------
How can these be fixed?
This comment has been removed by the author.
ReplyDeleteAdd the tag < version >2.5.1< / version > below the tag artifactId.
ReplyDelete