Thursday 23 November 2017

How to configure Jacoco plugin in Maven

Guys, for getting the unit test coverage report in SonarQube for code quality and analysis, let us look into how to use the Jacoco plugin for the same. In this post we'll see how to configure Maven with the Jacoco plugin. FYI Jacoco is a free code coverage tool for Java


In your main parent POM, let us enter the Sonar properties firstly, as follows :

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<!-- Sonar -->
<sonar.java.coveragePlugin>jacoco</sonar.java.coveragePlugin>
<sonar.jacoco.reportPath>${project.basedir}/target/jacoco.exec</sonar.jacoco.reportPath>
<sonar.language>java</sonar.language>
<drools.version>5.5.0.Final</drools.version> 
</properties> 

Now in the <pluginManagement> section, let us enter the configuration for the Jacoco plugin.

<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.2.201409121644</version>
<configuration>
<destFile>${sonar.jacoco.reportPath}</destFile>
<append>true</append>
</configuration>
<executions>
<execution>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>prepare-package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
<execution>
<id>post-unit-test</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>

Hope it helps guys. Until next time, ciao!

Automate regular backups of SonarQube's DB using bash script

Guys, this post will be useful if you are using SonarQube for code analysis and quality control. In today's post we will look into how to automate taking regular backups of SonarQube's back-end database.


For illustration, we will use MySql DB to store SonarQube's metadata which includes analysis parameters like code smells, bugs, code coverage, unit test coverage etc. In this case we host Sonar on a linux machine, so we write a bash script to take regular backups of the MySql DB. Take a look at a simple sample script below :

#!/bin/bash
# script for taking database dump of sonar

user="root";
hostname="localhost";
db_name="sonar";
dateformat=`date +%d-%m-%y`;

mysqldump --defaults-extra-file="/usr/local/cron_scripts/.my.cnf" -u $user -h $hostname sonar | gzip > /usr/local/mysql_dumps/sonar_dump_$dateformat.sql.gz

chmod 755 /usr/local/mysql_dumps/sonar_dump_$dateformat.sql.gz

As you see, we have used mysqldump to take dump of the database, zip it, append it with the current date and store it at the said location.

Taking dumps of Sonar can be extremely useful for the purpose of importing and exporting of a Sonar instance from one machine to another without losing the analysis history.

Change default javadoc output directory in Maven

When using the Maven javadoc plugin for generating javadoc for your project, we also have the option of changing the default output directory. As you know, by default the javadoc gets created within the project-folder/target/apidocs directory.

So, when updating the location of javadoc's output directory, use the <reportOutputDirectory> tag. Consider the illustration below :

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.9.1</version>
<configuration>
<additionalparam>-Xdoclint:none</additionalparam>
<reportOutputDirectory>E:\\Javadoc\${project.name}</reportOutputDirectory>
</configuration>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>

As you see in this case we have updated the javadoc output directory to a different drive itself i.e. E:\\Javadoc\${project.name}. Kindly check this link as well for additional reference.

Tuesday 31 October 2017

How to skip tests for specific module in a Maven build

In a Maven build of a multi module project, sometimes we may want to skip tests for only a specific module. For illustration, let's consider a multi module project with 10 modules and we want to skip tests only for 1 or 2 modules.

In such a scenario, enter the following in that module's pom whose tests we want to skip. We simply set the skipTests tag to true in the maven surefire plugin configuration.

<build>
        <plugins>
            <plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
        </plugins>
    </build>

Until next time, Ciao.

Monday 30 October 2017

Learn Deutsche - German verbs : Set 6

Hello folks. Presenting another fresh list of random Deutsche verbs from the word bank.


Set 6
bleiben : to stay
glauben : to believe
duschen : to shower
vergessen : to forget
küssen : to kiss
warten : to wait
backen : to bake
kochen : to cook
waschen : to wash
anrufen : to call

Friday 27 October 2017

Learn Deutsche - German verbs : Set 5

Hello folks. Presenting the latest batch of Deutsche verbs wordlist.


Set 5
helfen : to help
kaufen : to buy
probieren : to try
bringen : to bring
verlieren : to lose
gewinnen : to win
fliegen : to fly
halten : to stop
lernen : to learn
tragen : to carry

Learn Deutsche - German verbs : Set 4

Hello guys. Let's look into another fresh batch of 10 random German verbs.


Set 4
kosten : to cost
trinken : to drink
shcreiben : to write
nehmen : to take
lieben : to love
reisen : to travel
singen : to sing
antworten : to answer
essen : to eat
schlafen : to sleep

Related Posts Plugin for WordPress, Blogger...
eXTReMe Tracker