SonarQube and migration to multi-module project with preserving history - sonarqube

We're in process of migration of a single Maven project that has been analyzed in SonarQube 4.5.4 into a multi-module Maven project.
The SonarQube analyzing is going to be migrated to the Parent project so that the old and new modules would be analyzed all-in-one.
During the analyzing we receive an error:
'The project '...' is already defined in SonarQube but not as a module of project '...:Parent''
The obvious solution is to remove the old project from SonarQube, however it means removal of all historical information.
How can we achieve both goals:
migrate to multi-module project
keep history of analyzing of the existing project (that should be a child of the new multi-module project)
?
Thanks.

SonarQube does not allow to group several existing projects into a single one. So you won't be able to achieve your 2 goals.
The only thing you can do is to update the key of each existing project on SonarQube (for instance, you can add "_OLD" suffix on their key). This will allow you to:
Keep the history for those projects - but they won't evolve any longer
Make it possible to analyze successfully the new multi-module project
To know how to update project key, please read the documentation.

Related

sonar and maven multi-module project - can sonar analyze every module separately?

I have a multi-module project, and O want sonar to analyze each project by himself. For example, to check duplicated lines only in the same module and not compere to all the project code?
If you want them to be separate from SonarQube's point of view, then you have to scan them separately. SonarQube will not be "creating a different project in the same repo". It doesn't care what the source location is for each project.
So, in your build process that runs the scans, you'll simply have to "cd" into each submodule directory and run "sonar:sonar" (or use the sonar-scanner), specifying the module name for each. You'll need to ensure that the module name is a unique SonarQube project.

Edit Java source code before compile

I am new to gradle. I am looking forward to migrating from maven to gradle.
I had few requirements:
Existing project is maven based, and is generating a fat jar/uber jar. I am planning to split this into multiple projects, and creating smaller/thinner jars/libraries
I am currently evaluating the Multi-project Build support.
I have to also edit the Java source code, automatically, like making the java source modifications based on certain conditions
Publish the project as maven based, as other projects which need these split-up jars are still maven based.
I suppose Maven plugin can be used for publishing?
Would Gradle be a good, scalable solution for these two requirements which I am looking into currently?
Also please provide some pointers around these two topics.
Gradle has very good multi-project support, far better than Maven's. You can start with this documentation section
You can setup compilation of generated/auto-edited sources as well. Take a look at this forum post, discussing compilation of sources created from database using hbm2dao
You can setup publishing of projects using the Maven plugin. pom.xml files will be generated automatically

Unable to run SonarQube analysis of two projects with the same ids?

I have a situation like where i have two projects.
For one project i am successfully able to run analysis. 2nd project is new and it is completely using code and same structure and same modules of project 1 and we can say it is extension of Project 1. While i am running code analysis it is saying modules are already part of project 1
[ERROR] Failed to execute goal org.codehaus.mojo:sonar-maven-plugin:2.7.1:sonar
(default-cli) on project citi-sgp-au:
Module "com.xxxx.xxxx:xxxxxx" is already part of project "xxxx-xxx-xxx222"
-> [Help 1]
Any guidance on this?
SonarQube cannot analyze 2 different projects with the same id (e.g. groupId and artifactId).
You can change id of one of the two projects or use sonar.branch property.
From SonarQube Wiki:
sonar.branch - Manage SCM branches. Two branches of the same project are
considered to be different projects in SonarQube. As a consequence
issues found in a project A in a branch B1 are not linked to issues
found for this project A in a branch B2. Currently, there is no way to
resolve automatically issues of B2 when they are resolved in B1 as
again A-B1 & A-B2 are considered as separated project.
Because you are using the same code and same structure, I assume that the module of both projects end up having the same key. In SonarQube, it is not possible to have a module that belongs to several projects.
So the solution is to make sure that the modules of your 2nd project have unique keys.
Note: if you're using Maven, this is very simple: just make sure that your second project has a different groupId.

Sonar separate quality profile per component

I have a multi-module maven project and have it's modules as Sonar components.
Is it possible to set alerts separate per module/component, or Sonar considers the whole project? If not, what's the best way of having my maven modules as separate projects in Sonar, so that mvn sonar:sonar is only executed once. I use cobertura for report generation.
At the moment of writing this answer, that feature is not supported by Sonar.
If separate metrics needed you need to create a separate project and trigger a separate build from Jenkins and providing specific pom.xml file for desired module.

How to do continuous integration with Hudson for Maven 3 multi-module projects well?

It is my current impression that is impossible to do CI for a Maven 3 multi-module project well using Hudson (or Jenkins).
The situation seems to be that you have 2 realistic options of building a multi-module Maven 3 project with Hudson:
A freestyle project can also Build Maven projects, and with the incremental/recursive option it apparently should be able to deal with building only the necessary subtrees of the complete project tree.
A legacy, severly deprecated, with lots of warnings, Maven2/3 legacy build.
With the first option there is the significant disadvantage that your complete project looks like one big blob in Hudson, there is no visibility on the individual subprojects and there is no option for building individual subprojects and their dependees.
With the second option you have to basically swallow very little faith inducing warnings about legacy and "do not use" in order to find out that yes, it will build your multi-module project but the functionality of triggering subproject builds is completely broken and there is no intention of fixing this.
The only alternative I can figure out is to revert to Maven 2 for the build on the server, in which case the legacy plugin seems to work and even the individual sub-project builds can be triggered. But then I'm stuck on Maven 2.
I find my requirements to be rather conservative but I am completely stymied by the lack of Maven support in Hudson/Jenkins. Here's what I would expect:
ability to recognize multi-module projects and build them using Maven 3
ability to have "incremental" builds of such a multi-module project (i.e. only changed modules and its dependees)
ability to see the current status of the multi-module project and what sub-module has failed/succeeded/is unstable
The Maven project in question consists of about 84 Maven modules in a multi-module configuration with a common parent and a split into different subsystems. We are using Hudson 3.1.0.
Do I have any chance of achieving this?
Yes, it is impossible to do it well with the current Maven 2/3 project type.
I have done it well enough using a matrix / multi-configuration project type, and adding a "Module" axis manually. The configuration of the matrix job is a pain, and you have to remember to update your axis any time you add, remove or rename a module. But once configuration is complete, this solution works well for building. You can see the build and test results for each module separately, or integrated under the matrix job.
My colleague has been working on implementing Maven 3 multi-module functionality in Jenkins.
https://github.com/adamcin/maven-plugin
Not sure what the upstream acceptance status is.

Resources