Sonar refuses to analize multimodule project - maven

I have upgraded from Sonar 5.3 to 6.2 and a project X is giving me some weird errors at the sonar stage of the jenkins job (altough build finishes as STABLE).
The project is a standard multimodule maven java project.
Entering the project dashboard a single message appears on screen:
"No analysis has been performed since creation. The only available
section is the configuration."
But in the upper-right corner the red "FAILED" tag shows up. That leads to the Background tasks of the project and there is the failed task with this error log:
The project "com.foo:bar-submodule-1" is already defined in SonarQube
but not as a module of project "com.foo:bar". If you really want to
stop directly analysing project "com.foo:bar-submodule-1", please
first delete it from SonarQube and then relaunch the analysis of
project "com.foo:bar"
I do not want to delete the project and lose the historical data.
So the question is: How can i add a project Y (that is a submodule of project X but Sonar does not recognize it) as a submodule of project X?
EDIT 1
The parent project is the only one that has been analyzed through jenkins jobs.

Your problem is not that Sonar can't figure out your submodules, but the root issue is that there is another project/module with the same name conflicting with the project you are analyzing now. It happens, for example, when you extract a submodule as a standalone library and moves it as a root project and try to analyse the new project. Since it is a new project, but sometime in the past you had another project/module with the exact same name, it won't be able to finish the process. I have found three ways to fix this:
Delete the old project, if it is possible
This is a option that I use when I have analysed mistakenly new projects (with wrong parameters for example) or when I am migrating servers and still have some wrong configuration in place. You can do this in the project's Configuration/Administration menu, 'Delete project'.
Rename the old projects keys
This is my default option, since usually what I want is just keep the old analyses data for old submodules that we are moving to other projects or promoting to root modules. You can do this in the project's Configuration/Administration menu, 'Update key' option.
Updating your current project's keys
This option I use when the submodules conflict with other valid submodules (It can happen when you have different teams creating small libraries that happen to have the same keys). You can do this in two steps. First you need to update your project's keys following the option 2. The next step is to go to your project and update the modules and submodules names using the key sonar.moduleKey. The default value for this is : similar to sonar.projectKey, as especified here. Following these steps you won't lose all your records and old analyses.
I hope it helps.

Related

Issues in moving build configuration in teamcity

I am working on Team-city 9.x. I have some build failures in one of the release project. although we have disabled the build and we do not want to run the build.
I am trying to move the build to another project (Disabled builds) but I cannot move the build.
Since I am getting an error as below
So I created the same VCS roots same as the release project for disabled-build project but still I am getting the same error.
It sounds like the VCS root hasn't been created at a level that can be shared by both projects from it's current location.
If you move the original VCS root to a level that is above both the current project and the one you're moving it too, it can be shared by both and you'll be able to move the project.
I would move this to <Root project> initially to help you move the project and then determine the best location for it depending on where it's being used in other build configurations
Hope this helps

How to delete a project in SonarQube 5.3 if the search doesn't find it?

A few projects' analysis is failing with the following error:
org.sonar.api.utils.MessageException: Validation of project failed:
o The project "com.xxx.myproject:myproject-api-test" is already defined in SonarQube but not as a module of project "com.xxx.myproject:myproject". If you really want to stop directly analysing project "com.xxx.myproject:myproject-api-test", please first delete it from SonarQube and then relaunch the analysis of project "com.xxx.myproject:myproject".
However, I am unable to find the project on the SonarQube frontend, therefore can't delete it.
I have tried browsing directly to what I imagined the URL for that project to be. That worked for one, but I have more projects with this problem and for those a URL is not available.
One more thing: I use multi-module projects.
You need to get into the DB and do it from there. I did have a script on a previous job to fix this issue :(. I think I can explain what happened there without seeing anything in the DB.
You had a multi-module maven project which was running nice and easily.
Someone run a sonar build on one of the submodules. This updated the submodule in Sonar to become a top level module.
Someone deleted the submodule from sonar (UI) which actually doesn't delete it, but marks it as deleted. And this is also the reason why you cannot find it from the sonar UI.
What I remember doing was to
log on the database
find the row describing the top level module
find the row describing the submodule that is giving you trouble
update the row of the submodule to become a submodule (I remember there was a 'type' column or similar) and update the parent id from the step on 2. You might also un mark this as deleted.
I'm sorry that I cannot be of more help with the specific SQL queries.
I'm using sonarqube version 5.1.x and ran into same problem. Executed mvn sonar:sonar on maven sub-module. To fix it, I updated the kee column products table for that project and set the value to :. After that logged in as admin into UI and did a bulk delete. Re-ran mvn sonar:sonar and able to verify the fix.

TeamCity Dependency not sticking around

I'm sure this is a dumb mistake on my part but I can't find the right answer.
I have a project that has a snapshot dependency on another project. For sake of discussion website is dependent on toolkit.
Monitoring the build folder:
c:\programs\Teamcity\buildagent\work
I see the toolkit get built and the folders all exist as expected:
c:\programs\teamcity\buildagent\work\toolkit
Then the website build kicks off and the folder above gets deleted before the website build starts.
This results in the website saying the reference couldn't be found. What setting am I missing?
Using TeamCity 7.1.2, working on getting it upgraded to 8.1 but it requires some internal evaluation first.
Don't think its a version issue. How do both of your builds know where to put the artefacts at . For ex teamcity normally builds stuff at c:\programs\teamcity\buildagent\work****\toolkit , not at c:\programs\teamcity\buildagent\work\toolkit ?
Also, if your targets are dependent upon each other across builds, (1) have you setup any artefact dependencies or (2) any process that does not read of a shared agent workspace ? or (3) forcing both builds to run from the same directory
See if both your builds are running on the same target "folder name". In case they are , deselect any option that "cleans up build targets" before they run.
Also, you might want to check your build files to see if they have any code to clean directories before they start to run

Keep project history when transforming project in module in SONARQUBE

I recently attempted to change a sonar project into another project module.
I found out in SONAR-4245 that the existing project has to be delete in order to have it in a module.
However, I would like to keep the project history.
Is that possible ?
Unfortunately that's not possible, and we don't plan to make it possible for the moment.

SonarQube: Check if a project with the same key already exists while first analysis/build

I am building my projects with Jenkins and analyze them with SonarQube.
The problem I am trying to fix without writting my own Plugin is the following:
1.) Jenkins starts a build of a new project (never built or analyzed an SonarQube before)
2.) SonarQube analysis is triggered
3.) SonarQube shell check if a project with the same key already exists
4a.) If it already exists: Abort analysis and throw error message
4b.) If it not exist: Continue the analysis as a normal analysis
Or in other words: If a Project is analyzed for the first time, I want SonarQube to make sure that there is no other project already existing with the same key this new project uses. The goal is to avoid overwritting existing projects by a complete other project
If a project has been already analyized and the new analysis would be a like "updating the old results" i don't want any error message to show up.
Can i simply install a plugin? Must i change things within the pom.xml? Is there a way? And if yes: how does it work?
(I know the possibility to get the buildnumber of the last successful build in Jenkins. And if it would be greater or equal 1 there would be no reason for my check anymore. If it's not: i need my check)
Thanks for your help :)
You can use the /api/resources?resource=project-key Web Service from a script to check if the given project key already exists (if not, the WS will answer with a 404).
However, as #andre-stannek said: in the end it is your responsibility to make sure that 2 projects don't use the same key. There is no way for SQ to know if the analyzed project is an update of an existing project or not.

Resources