In the next series of sonar, we will see
how we can integrate sonar with maven and use maven command in analyzing the
source code of a project and display the results on the sonarqube console.
1. Make sure JDK,Maven and Sonar are
available ( with sonar running ).
2. Make the changes to the global maven
setting.xml file available at location ~/.m2
3. Add the pluginGroups as,
<pluginGroups>
<pluginGroup>org.sonarsource.scanner.maven</pluginGroup>
</pluginGroups>
4. Add the Profile pointing the location of
the sonar console as,
<profile>
<id>sonar</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<sonar.host.url>http://puppet.jas.com:9000</sonar.host.url>
</properties>
</profile>
4. Once the changes are done, Move to you java
application and run,
[puppet@root$:/work/testing/javaee7-simple-sample]$
mvn clean verify sonar:sonar
[INFO] Scanning for projects...
[INFO]
[INFO]
------------------------------------------------------------------------
[INFO] Building javaee7-simple-sample
1.11-SNAPSHOT
[INFO]
------------------------------------------------------------------------
[INFO]
[INFO] --- maven-war-plugin:2.3:war
(default-war) @ javaee7-simple-sample ---
[INFO] Packaging webapp
[INFO] Assembling webapp
[javaee7-simple-sample] in
[/work/testing/javaee7-simple-sample/target/javaee7-simple-sample]
[INFO] Processing war project
[INFO] Copying webapp resources
[/work/testing/javaee7-simple-sample/src/main/webapp]
[INFO] Webapp assembled in [63 msecs]
[INFO] Building war: /work/testing/javaee7-simple-sample/target/javaee7-simple-sample.war
[INFO]
[INFO]
------------------------------------------------------------------------
[INFO] Building javaee7-simple-sample
1.11-SNAPSHOT
[INFO]
------------------------------------------------------------------------
[INFO]
[INFO] --- sonar-maven-plugin:3.0.2:sonar
(default-cli) @ javaee7-simple-sample ---
[INFO]
User cache: /root/.sonar/cache
[INFO] SonarQube version: 4.5.7
[INFO] Default locale: "en_US",
source code encoding: "UTF-8"
[INFO] [02:21:17.060] Load global
referentials...
[INFO] [02:21:17.393] Load global
referentials done: 334 ms
[INFO] [02:21:17.411] User cache:
/root/.sonar/cache
[INFO] [02:21:17.420] Install plugins
[INFO] [02:21:17.739] Install JDBC driver
[INFO] [02:21:17.743] Create JDBC
datasource for jdbc:h2:tcp://localhost/sonar
[INFO] [02:21:18.596] Initializing
Hibernate
[INFO] [02:21:19.930] Load project
referentials...
[INFO] [02:21:20.315] Load project
referentials done: 385 ms
[INFO] [02:21:20.315] Load project settings
[INFO] [02:21:21.131] Loading technical
debt model...
[INFO] [02:21:21.151] Loading technical
debt model done: 20 ms
[INFO] [02:21:21.153] Apply project
exclusions
[INFO] [02:21:21.395] ------------- Scan javaee7-simple-sample
[INFO] [02:21:21.398] Load module settings
[INFO] [02:21:21.720] Loading rules...
[INFO] [02:21:22.089] Loading rules done:
369 ms
[INFO] [02:21:22.113] Configure Maven
plugins
[INFO] [02:21:22.170] No quality gate is
configured.
[INFO] [02:21:22.329] Initializer
FindbugsMavenInitializer...
[INFO] [02:21:22.330] Initializer
FindbugsMavenInitializer done: 1 ms
[INFO] [02:21:22.330] Base dir:
/work/testing/javaee7-simple-sample
[INFO] [02:21:22.330] Working dir:
/work/testing/javaee7-simple-sample/target/sonar
[INFO] [02:21:22.330] Source paths:
src/main/webapp, pom.xml, src/main/java
[INFO] [02:21:22.330] Binary dirs:
target/classes
[INFO] [02:21:22.331] Source encoding:
UTF-8, default locale: en_US
[INFO] [02:21:22.331] Index files
[INFO] [02:21:22.363] 4 files indexed
[INFO] [02:21:22.414] Quality profile for
java: Sonar way
[INFO] [02:21:22.427] Sensor
JavaSquidSensor...
[INFO] [02:21:22.600] Java Main Files AST
scan...
[INFO] [02:21:22.603] 4 source files to be
analyzed
[INFO] [02:21:22.765] 4/4 source files
analyzed
[INFO] [02:21:22.767] Java Main Files AST
scan done: 167 ms
[INFO] [02:21:22.768] Java bytecode scan...
[INFO] [02:21:22.790] Java bytecode scan
done: 22 ms
[INFO] [02:21:22.790] Java Test Files AST
scan...
[INFO] [02:21:22.790] 0 source files to be
analyzed
[INFO] [02:21:22.791] Java Test Files AST
scan done: 1 ms
[INFO] [02:21:22.791] 0/0 source files
analyzed
[INFO] [02:21:22.795] Package design
analysis...
[INFO] [02:21:22.799] Package design
analysis done: 4 ms
[INFO] [02:21:22.822] Sensor
JavaSquidSensor done: 395 ms
[INFO] [02:21:22.822] Sensor
QProfileSensor...
[INFO] [02:21:22.826] Sensor QProfileSensor
done: 4 ms
[INFO] [02:21:22.826] Sensor
InitialOpenIssuesSensor...
[INFO] [02:21:22.863] Sensor
InitialOpenIssuesSensor done: 37 ms
[INFO] [02:21:22.863] Sensor
ProjectLinksSensor...
[INFO] [02:21:22.866] Sensor
ProjectLinksSensor done: 3 ms
[INFO] [02:21:22.867] Sensor
VersionEventsSensor...
[INFO] [02:21:22.872] Sensor VersionEventsSensor
done: 4 ms
[INFO] [02:21:22.872] Sensor
FileHashSensor...
[INFO] [02:21:22.873] Sensor FileHashSensor
done: 1 ms
[INFO] [02:21:22.873] Sensor
SurefireSensor...
[INFO] [02:21:22.874] parsing
/work/testing/javaee7-simple-sample/target/surefire-reports
[WARN] [02:21:22.874] Reports path not
found: /work/testing/javaee7-simple-sample/target/surefire-reports
[INFO] [02:21:22.874] Sensor SurefireSensor
done: 1 ms
[INFO] [02:21:22.874] Sensor Maven
dependencies...
[INFO] [02:21:22.897] Sensor Maven
dependencies done: 23 ms
[INFO] [02:21:22.897] Sensor CPD Sensor
(wrapped)...
[INFO] [02:21:22.897] JavaCpdEngine is used
for java
[INFO] [02:21:22.898] Cross-project
analysis disabled
[INFO] [02:21:22.917] Sensor CPD Sensor
(wrapped) done: 20 ms
[INFO] [02:21:23.018] Execute decorators...
[INFO] [02:21:23.121] Store results in
database
[INFO] [02:21:23.208] ANALYSIS SUCCESSFUL,
you can browse
http://puppet.jas.com:9000/dashboard/index/org.javaee7.sample:javaee7-simple-sample
[INFO] [02:21:23.255] Executing post-job
class org.sonar.plugins.core.issue.notification.SendIssueNotificationsPostJob
[INFO] [02:21:23.255] Executing post-job
class org.sonar.plugins.core.batch.IndexProjectPostJob
[INFO] [02:21:23.272] Executing post-job
class org.sonar.plugins.dbcleaner.ProjectPurgePostJob
[INFO] [02:21:23.283] -> Keep one
snapshot per day between 2016-07-27 and 2016-08-23
[INFO] [02:21:23.284] -> Keep one
snapshot per week between 2015-08-26 and 2016-07-27
[INFO] [02:21:23.284] -> Keep one
snapshot per month between 2011-08-31 and 2015-08-26
[INFO] [02:21:23.284] -> Delete data
prior to: 2011-08-31
[INFO] [02:21:23.288] -> Clean
javaee7-simple-sample [id=1]
[INFO]
------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO]
------------------------------------------------------------------------
[INFO] Total time: 38.600 s
[INFO] Finished at:
2016-08-24T02:21:23-04:00
[INFO] Final Memory: 30M/319M
[INFO] ------------------------------------------------------------------------
Once the Build is success we can see the
results in the console as,
More to Come, Happy learning J
No comments :
Post a Comment