1

I am considering the implementation of a Code Quality tool for our team's Projects.

SonarQube seems to be a good choice. I haven't gotten the ideal workflow figured out yet (we use SVN and Maven Projects and have a Jenkins server running the tests on every commit).

Aside from the importance of being able to analyse the quality of the current commit, historical evolution is also very interesting.

Given that we already have a few years of commits, is it possible, when setting up the project, to request a retrospective analysis of those commits, or will SonarQube only work for the commits from the day it is installed onwards?

mmalmeida
  • 1,037
  • 9
  • 27

2 Answers2

1

SonarQube only displays data uploaded by scanners. You can checkout to any commit (read more here: How to checkout a specific Subversion revision from the command line?) and next execute a scanner. The used scanner depends of what kind of a build tool you use:

The analysis result will be pushed to a SonarQube server. Unfortunately, it is always treated as the last version of the application, so you cannot "insert" analysis of some old commits to the project history. But do you really need it? Scanners always analyze all sources. If somebody added some code three years ago and nobody deleted it, then it will be available on the server. If the code is deleted, then you shouldn't spend time on analyzing something, what doesn't exist anymore. That's why SonarQube always shows the last state of the project.

You can read a good blog post written by Fabrice Bellingrad (April 06, 2016): Stop planning; fix the leak!

Read more about SonarQube Architecture and Integration.

agabrys
  • 8,728
  • 3
  • 35
  • 73
  • Thanks for the tip! Could you build up on this response just to clarify the following: 1. what you mean by "checking out to any commit and execute scanner". 2. If it is possible that the scanners publish the results into the same project, with the original commit number/date (i.e. adding the historical data the same project). – mmalmeida Apr 15 '18 at 10:11
  • @mmalmeida I extended the answer. I hope it is more clearly right now. – agabrys Apr 15 '18 at 18:46
0

Yes, this is possible using the sonar.projectDate analysis parameter. Its purpose is precisely what you are asking for.

Quote from the docs:

Assign a date to the analysis. This parameter is only useful when you need to retroactively create the history of a not-analyzed-before project. The format is yyyy-MM-dd, for example: 2010-12-01. Since you cannot perform an analysis dated prior to the most recent one in the database, you must analyze recreate your project history in chronological order, oldest first.

You could for example check out your last 10 version tags in chronological order (oldest first!). For each tag run the analysis with sonar.projectDate set to the date the tag was created.

friederbluemle
  • 33,549
  • 14
  • 108
  • 109