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.
Related
I am trying to analyze one Maven project (with the SonarQube Scanner for Maven) and I am getting the following validation error: Module "com.company:module1" is already part of project "com.company".
I would like to ask you if there is a way to turn this validation off or what should I do in order to analyze the project the second project without deleting the first one.
There's no way to turn this validation off; component keys must be unique across the instance. To be able to analyze both projects, you must remove (or exclude) the module from one of the projects. If the already-analyzed project is the one that loses the module, make your configuration changes, re-analyze, and then you should be able to analyze the second project.
I am trying to build my Java project into two different version, each one based on different versions on the same dependencies. Specifically, my project A requires a dependency B, which has two different versions (e.g. v1 and v2). I am looking to build project A with each dependency version of B and get as artifact two different jars: A-v1.jar and A-v2.jar. The source code is the same so I wouldn't want to duplicate it into two different Maven projects, as I am looking to scale it when new versions of B will be released.
What I have tried so far: I defined two build profiles v1 and v2 where I have specified the dependency B version. This works fine as I can build the two profiles, but the issue is that I have no idea how to tell Maven to add a version number to the build artifact. It always builds project A into A-1.0.jar, where 1.0 is the project A version in the pom.
One update of my investigation: I have added a finalName element in the build section of my parent pom to override the default artifacts naming. Now the naming will be like ${artifactId}-${project.version.mycustomver}, where project.version.mycustomver property is defined in each build profiles. This seems to generate the correct naming of jars, however maven-install-plugin is changing the artifacts names back to ${artifactId}-${version}. No idea why and how to avoid it.
I appreciate any suggestion. Thanks,
DanP
You can either use classifier which is somehow made for that.
But you should also be able to change the version using a property that is overridden in the profiles.
Since you need two distinct POMs, one per "version" of your project, you in fact need two projects. However, you can have one normal version A. And a second one which is empty but uses dependency management to exclude and replace the dependencies that changes from A-v1 to A-v2.
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.
Very new to Maven, can someone please explain to me the difference between using maven modules vs just adding a dependency to your maven project to another maven project in your workspace? When would you use one over the other?
A dependency is a pre-built entity. You get the artifact for that dependency from Maven Central (or Nexus or the like.) It is common to use dependencies for code that belongs to other teams or projects. For example, suppose you need a CSV library in Android. You'd pull it as a dependency.
A Maven module gets built just like your project does. It is common to use Maven modules for components that the project owns. For example, maybe your project creates three jar files.
A dependency can be thought of as a lib/jar (aka Artifact in Maven parlance) that you need to use for building and/or running your code.
This artifact can either be built by your one of the modules of your multi module project or a third party pre-build library (for example log4j).
One of the concepts of maven is that each module is going to output a single artifact (say a jar). So in case of a complex project it is good idea to split your project to multiple modules. And these modules can be dependent on each other via declared dependencies.
See http://books.sonatype.com/mvnex-book/reference/multimodule-sect-intro.html for example of how a web app is split to parent and child modules and how they are linked.
One of the most confusing aspects of Maven is the fact that the parent pom can act as both a parent and as an aggregator.
99% of the functionality you think about in Maven is the parent pom aspect, where you inherit things like repositories, plugins, and most importantly, dependencies.
Dependencies are hard, tangible relationships between your libs that are evaluated during each build. If you think of your software as a meal, it's basically saying A requires ingredient B.
So let's say you're preparing lasagne. Then your dependency chain would look something like this:
lasagne
<- meatSauce
<- groundBeef
<- tomatoPaste
<- cheese
<- noodles
The key thing is, each of the above items (meatSause, groundBeef, cheese, etc) are individual builds that have their individual set of dependencies.
By contrast, the only section of your pom that pertains to aggregation is the modules section:
<modules>
<module>meatSauce</module>
<module>groundBeef</module>
<module>tomatoPaste</module>
<module>cheese</module>
<module>noodles</module>
</modules>
Aggregation simply tells your build engine that it should run these 5 builds in rapid succession:
groundBeef -> tomatoPaste -> cheese -> noodles -> meatSauce
The main benefit of aggregation is the convenience (just click build once) and ensuring the builds are in the correct order (e.g. you wouldn't want to build meatSauce before tomatoPaste).
Here's the thing though: even if you organize the libs as standalone projects without module aggregation, your build will still come out the same provided you build in the correct order.
Moreover, both Jenkins and Eclipse have mechanisms for triggering builds if a dependent project has changed (e.g. changing groundBeef will automatically trigger meatSauce).
Therefore if you're building out of Jenkins or Eclipse, there is no need for aggregation
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.