martes, julio 17, 2012

JaCoCo in Maven Multi-Module Projects

Can you blow my whistle baby, whistle baby, Let me know Girl I'm gonna show you how to do it And we start real slow You just put your lips together. (Whistle - Flo Rida)
Code coverage is an important measure used during our development that describes the degree to which source code is tested.

In this post I am going to explain how to run code coverage using Maven and JaCoCo plugin in multi-module projects.

JaCoCo is a code coverage library for Java, which has been created by the EclEmma team. It has a plugin for Eclipse, and can be run with Ant and Maven too.

Now we will focus only in Maven approach.

In a project with only one module is as easy as registering a build plugin:

And now running mvn package, in site/jacoco directory, a coverage report will be present in different formats.

But with multimodule projects a new problem arises. How to merge metrics of all subprojects into only one file, so we can have a quick overview of all subprojects? For now Maven JaCoCo Plugin does not support it.

There are many alternatives and I am going to cite the most common:

  • Sonar. It has the disadvantage that you need to install Sonar (maybe you are already using, but maybe not).
  • Jenkins. Plugin for JaCoCo is still under development. Moreover you need to run a build job to inspect your coverage. This is good in terms of continuous integration but could be a problem if you are trying to "catch" some piece of code that has not covered with already implemented tests.
  • Arquillian JaCoCo Extension. Arquillian is a container test framework that has an extension which during test execution can capture the coverage. Also a good option if you are using Arquillian. The disadvantage is that maybe your project does not require a container.
  • Ant. You can use Ant task with Maven. JaCoCo Ant task can merge results from multiple JaCoCo files result. Note that is the most generic solution, and this is the chosen approach that we are going to use.
First thing to do is add JaCoCo plugin to parent pom so all projects could generate coverage report. Of course if there are modules which does not require coverage, plugin definition should be changed from parent pom to specific projects.

Next step is creating a specific submodule for appending all results of JaCoCo plugin by using Ant task. I suggest  using something like project-name-coverage.

Then let's open generated pom.xml and we are going to insert required plugins to join all coverage information. To append them, as we have already written we are going to use a JaCoCo Ant task which has the ability to open all JaCoCo output files and append all their content into one. So first thing to do is download the jar which contains the JaCoCo Ant task. To automatize download process, we are going to use maven dependency plugin:

During process-test-resources phase Jacoco Ant artifact will be downloaded and copied to target directory, so can be registered into pom without worrying about jar location.

We also need a way to handle Ant tasks from Maven. And this is as simple as using maven antrun plugin, which you can specify any ant command in its configuration section. See next simple example:

Notice that into target tag we can specify any Ant task. And now we are ready to start configuring JaCoCo Ant task. JaCoCo report plugin requires you set the location of build directory, class directory, source directory or generated-source directory. For this purpose we are going set them as properties.

And now the Ant task part which will go into target tag of antrun plugin.

First we need to define report task.

See that org.jacoco.ant.jar file is downloaded by dependency plugin, you don't need to worry about copying it manually.

Then we are going to call report task as defined in taskdef section.

Within executiondata element, we specify locations where JaCoCo execution data files are stored. By default is target directory, and for each project we need to add one entry for each submodule.

Next element is structure. This element defines the report structure, and can be defined with hierarchy of group elements. Each group  should contain class files and source files of all projects that belongs to that group. In our example only one group is used.

And finally we are setting output format using html, xml and csv tags.

Complete Code:

And now simply run mvn clean verify and in my-project-coverage/target/coverage-report, a report with code coverage of all projects will be presented.

Hope you find this post useful.

We Keep Learning,

Download Code

42 comentarios:

Mickael Istria dijo...

I suggested a solution to this issue here: Unfortunately, it did not get a lot of interest. Maybe you could add your thoughts on this issue, hoping it will encourage developers to look at it with the priority it deserves.

Unknown dijo...

Hi. Can you give more information on how the coverage module pom should look like? Or even batter if you can give a small project example. I'm a bit new to maven, and right now I get an error that ${jacoco.version} is undefined and also I do not understand how the whole pom should look like and whether I should create any other files other then pom

Unknown dijo...

Hi Yury have you tried the example provided in the post that you can download from the bottom? It should work. Also I use this approach in NoSQLUnit project you can take a look at poms there, if you have any problem, please do not hesitate to continue asking me.

Babu Bheemaraj dijo...

I tried the same thing with a multi-module project where there's a single .exec file obtained with integration testing of the application.

Also, i made a new maven project to collect instrumented jars for use with the report task. (just like you showed here)

However, the generated html report shows zero coverage for all classes.

Any hints /suggestions?

ati dijo...

Tried it and it works! Thank you for providing this example!

Dr. Lina dijo...

Jual obat aborsi cytotec
Jual obat aborsi bandung
Jual obat aborsi batam
Jual obat aborsi makassar

Jual obat aborsi malang
Jual obat aborsi palembang
Jual obat aborsi semarang

Jual obat aborsi jakarta
Jual obat aborsi bekasi

Jual obat aborsi surabaya ,Semarang, Jogja, yogyakarta,Malang, Surabaya, Jakarta, Bandung, Bekasi, Batam, Palembang dan Makassar.

Unknown dijo...

تستخدم شركة الاول افضل معدات تنظيف المنازل فيمكنك الاستعانة بنا لتحظى بافضل تنظيف للمنازل ولدينا فروع تغطى جميع المملكة فشركة الاول تعد افضل
شركة تنظيف بمكة
وافضل شركة تنظيف بالاحساء

افضل شركة تنظيف سجاد بالرياض

شركة صيانة مكيفات بالرياض

yanmaneee dijo...

michael kors purses
reebok outlet
cheap jordans
bape clothing
yeezy shoes
chrome hearts outlet
balenciaga trainers
christian louboutin outlet
nike air max

Assignment Help dijo...

You can connect with our team regarding any academic writing services at any hour of the day and we provide you the best and plagiarism free economics dissertation help assignment.
history dissertation help

tom554 dijo...

Hey, your blog is very informative. It is nice to read such high-quality content. Attractive information on your blog, thank you for taking the time and share with us. ABC assignment Essay help delivers high-quality content for all your subjects.

assignmentauthors dijo...

This figure is obtained after the comparison using this formula =MIN (B4:B24). freelance writer for hire

James Wick dijo...

Take Assignment help Ireland services to finish your work without any stress. If you have no one to ask your queries, use Assignment help services and get experts’ guidance for your concerns.
Assignment help Saudi Arabia
assignment help Hong Kong
assignment help Kuwait
assignment help United Arab Emirates

Assignment Help dijo...

Use Assignment Help services in Australia to get the services of professional academic writers easily. Enhance your chances of getting A+ grades in all project submission using online assignment writing services.

goingF dijo...

Glossary of nautical terms

Jasmine Joe dijo...

Nice Post! Are you overburdened with loads of electrical engineering assignments? Do never-ending (seems to be) theory classes, labs, practical sessions and industrial training gobble up much of your time? This is why brings electrical engineering assignment help services for U.S. students with the aim of sharing their academic burden. Electrical Engineering is a promising subject given the scope of research and applications. It mainly deals with large scale electrical systems and how they operate. In this branch, you need to study various aspects of electricity, electromagnetism, and circuits. Get the help from assignment assistance.

Unknown dijo...

Hasten Cleanse LLC of Houston, Texas, USA produces a powerful product for tank cleaning texas in the petrochemical sector. We strive to deliver a quality product with professionalism unrivaled in the marketplace.
We will do whatever it takes to be your vendor of choice in the hydrocarbon cleanup arena.

ramma dijo...

Foundation repair is what we’re really passionate about, but we do offer some other very noteworthy services. if we are on-site fixing your Foundation, Please Feel Free To Inquire About The Following Value-Added Services.

edmonton rooftop repair
Rooftop Repair
Gutter cleaning
Foundation Repair
Ramma Foundation Repair, we’ve got it covered!

Assignment Help dijo...

If you are looking for Online Assignment Help then you are at right place. We provide assignment help to complete your assignments on-time. We have a team of expert academic content writers who are always ready to complete your assignment in relevant manner.

alex dijo...

The main causes behind the quickbooks error 1603 are either the incomplete or corrupt QuickBooks software installation or the attack or virus or malware which corrupts the QuickBooks files. To resolve this issue, the user must download and install the QuickBooks InstallTool.exe file in the system as soon as he can to avoid further damage. The user can also uninstall and then re-install the updated version of the QuickBooks desktop software. this will ensure that you won’t face QuickBooks Error 1603 again but still, if you want professional help, you can contact with the QuickBooks support team.

hpprintercare dijo...

WPS Pin is a number this is commonly used for connecting your device wirelessly to a printer. It is basically a complex combination of numbers that you have to enter while connecting your device. You can find this number on the LED screen of your printer.WPS pin will keep your printer protected from connection to any other system. If any other system with active Wi-Fi will try to connect with your printer then it will ask for WPS pin. If the person will enter the wrong pin then the printer automatically denies the connection. To connect the printer through wireless it is mandatory to enter the correct pin.

wps pin hp printer
what is the wps button
wps pin printer
wps pin on hp printer
wps pin for hp printer
what is the wps button
where to find wps pin on hp printer

Assignment Help Australia dijo...

Students can take experts' assistance via Assignment Help services from the Australian service providers. Professional subject matter experts will help you to write your papers before the due dates even if you have issues of timing or quality content.
My Assignment Help
Assignment Help Online
Online Assignment Help
Assignment Help Australia

Olivia Crew dijo...

You had me engaged by reading and you know what? I want to read more about that. That's what's used as an amusing post.
read more:- Accounting Assignment Help

James Wick dijo...

Assignment Help allows scholars to establish a perfect connection with subject matter experts in Saudi Arabia. Solve all your questions without any issues using assignment writing help from the best service provider.
Assignment Help Online
Online Assignment Help

Olivia Crew dijo...

You Engaged Me All Through the Reading and Guess What? I Want to Read More on It. That’s What is Called A Post That Engages. MyAssignmentHelpAu is Providing Online Assignment Help in Australia From the Qualified Expert. I Have Written Many Contents on Case Study Help, Essay Writing Service, Cdr Report Writing, Proofreading Services, and More.
read more:- Assignment Help

seekclip | animated Video Creator dijo...

We are video creator company. we certified academic writer, professional and creative business plan developer. I hold Doctoral Degree with over 8years experience as a Job Briefing Specialist and Recruiter for topmost firm across USA, Canada and Europe
seekclip | animated Video Creator

Unknown dijo...

Ramma foundation is a company and a foundation that provide crack repair snow remove and gutter clean service. We are the crack repair foundation in Alberta Edmonton. We provide services like crack repair, gutter clean services, show removal, in short we are the foundation repair in Edmonton. If you are worried about the cracks on your home do not worry we are here to get it repair. If you are worried about snow on your roof, we can remove it. We are here to clean you gutter. foundation repair Edmonton

Assignment help dijo...

accounting help ,
online accounting assignment help ,
accounting assignment help ,
online accounting assignment help ,

Assignment help dijo...

Assignment Help ,
Assignment Help Online ,
Online Assignment Help ,
Assignment Help ,
Buy Assignment ,
Cheap assignment help ,
assignment help australia ,
assignment helper ,
homework help ,

Assignment Help dijo...

Choose Assignment Help when you have no one to ask your concerns while studying at American universities. Students can connect with professional academic writers using online assignment writing services and discuss their concerns even staying at home. You don’t need to make any physical contact with anyone when you have the option of online services.
Assignment Helper | Assignments Help | Help with assignment dijo...

In this blog, we will be casting light upon the latest updates on the Facebook Algorithm in 2020. The following content is an effective medium for the Brands who want to optimize their opportunity on social media considering Facebook advertising and formulating social media strategies in the new decade.

FB Latest Algorithm Update 2020
Facebook Algorithm Work In 2020
facebook changes
facebook algorithm
facebook algorithm change
facebook bypass

Law Assignment dijo...

Law Assignment Help dijo...

Holmes institute has implemented Holmes Blackboard
 in order to impart all educational resources for its students. Holmes blackboard acts as virtual blackboard and contain all required information for the students. Blackboard holmes login can be found on college site and can be used through login and password provided by the college. Blackboard holmes is one of the most advanced e-learning system offered by colleges in Australia. Students make holmes blackboard login so as to take out all assignment information and study class slides. Holmes Institute blackboard contain all information on course such as unit outline, assignment details and marking criteria etc. Holmes college blackboard is also used by the students to make their submission of assignment as well. Holmes blackboard is quite similar to the RMIT blackboard or Swinburne blackboard provided in their college for information access. Holmes Blackboard sydney has been recently updated to include some of the latest features wherein blackboard ultra has been launched which allow faster access to users.

blackboard holmes login
Holmes blackboard
blackboard holmes
holmes blackboard login

Law Assignment dijo... is known worldwide for its excellent quality Business Law Assignment Help services and affordable rates. Many of students have trusted our writing services throughout their academic years. Business Law Essay Assignment Help is one of the best services that can offer to law students.
Business Law Assignment Help
Business Law assignment
Business Law help
Business Law Homework
Business Law term paper
Business Law thesis
Business Law coursework

Law Assignment dijo...

Law assignment help website

Law assignment help,
Online Law Assignment Help,
Assignment help,

Law Assignment dijo...

Taxation law assignment help
taxation assignment help
Taxation assignment expert online
Taxation assignment writer

Law Assignment dijo...

accounting help ,
online accounting assignment help ,
accounting assignment help ,
online accounting assignment help ,

Smith Jonshone dijo...

Choosing the right Rehab Centers Near Me is life-changing decision. But how to select? These following factors to consider can help you to choose the best.

herryjhon dijo...

No passenger wants to miss the Flight tickets when they’re at cheap rates! For getting more comprehensive assistance related to Chaepest Ticket, you can call our travel specialists of Emirates Toll Free. They will guide you with all your queries or inquiries and will support you in getting the best deals of flights ticket

herryjhon dijo...

I’m highly impressed by the piece of thoughts you have shared on this portal. all the best, Looking for great deals and offers on air tickets? We all know that it is very hard and stressful to find these, so for your easy access, you only have to visit at Allegiant Airlines Low Fare Calendar and will provide you exciting offers and deals within minutes.

Whole Sales King dijo...

SHR Capital A Source of Free Forex Trading Tips in Abu Dhabi Operated by a team of Forex advisors and technical experts, we are united by one vision.
Best Forex trading course in Abu Dhabi

Digits me dijo... Each version of the Microsoft Office Setup needs a product code to complete its activation process. The world is full of cybercriminals, and various online thefts alongside online data leaks are increasing day by day. Get Microsoft Office setup from office setup, by entering the product key and logging into your account. McAfee antivirus offers complete protection to their users for securing their data against malware The digital world is communicated through the internet, and it’s the major source of various information circulated on the web McAfee Antivirus is the world’s highly used Antivirus programs that remove the malware and infection and avoids the chances of security threats

sam dijo...

Thanking for sharing Effective article. This is more helpful for reader. All types of coursework help for university level students as well as high school level students at affordable price. Get help quickly from Quick Assignment help.
Economics assignment help by expert professional at low price.