Multiple views of same project in SonarQube - java

Is there a way to have multiple views of the same java project which is being built by go-server in seperate pipelines with each pipeline building different git branch.
go-job : mvn sonar:sonar -Dsonar.host.url=http://localhost:9000
Each pipeline once successfully built overwrites previous view since the maven project is same. Wondering if I can differentiate sonar project using branch identifier or via other command parameter so that overwrite doesnt happen.

To analyze multiple instances of the same project, you can use the sonar.projectKeyproperty to differentiate the project.
Example: mvn sonar:sonar -Dsonar.projectKey=my-first-project-key

I have encountered same issue and found solution, hope this will help someone.
Whatever project key is generated while login (token generated), you can get the same token and build your project like below. I assume that you are able to view sonar dashboard.
Assume you have 3 projects
A project
B project
C project
Build your A project as
mvn sonar:sonar -Dsonar.projectKey=A -Dsonar.host.url=http://localhost:9000 -Dsonar.login=your token goes here
Build your B project as
mvn sonar:sonar -Dsonar.projectKey=B -Dsonar.host.url=http://localhost:9000 -Dsonar.login=your token goes here
and similarly build third one as well. Here what exactly is happening, -Dsonar.projectKey will take the project and it will post the generated report for given project to the token provided for localhost:9000 url. So how many projects you have it will show the reports for all in the sonar dashboard.
please try this and if this works then hit the like button :)

Related

Is it possible to run sonar analysis on all children but NOT parent of a multimodule Maven project?

I'm curious if it's possible to build and analyze the submodules of my multi-module maven project with a single command.
For the time being I have a single maven project with 3 separate services underneath it. Think of it like a small-scale monorepo.
Currently when I build them I can run a single mvn clean install from the top-most project and get a full build of everything with distinct JaCoCo analysis of all 3 services. In other maven projects where I already only have a single service I can simply run mvn clean install sonar:sonar but when I run it in my multi-module project it only executes at the top most level and analyses all 3 services as a single project in Sonar/SonarQube.
This answer seems to indicate it's impossible to do the same thing for a multi-module build with a single command but it's also a very old answer and things may have changed since then but with codehaus shutdown I don't think I can find that jira issue easily.
Also trying to implement the answer to that question using pluginManagement and enabling/disabling skip in parent/child modules doesn't seem to be working since sonar sees the parent as being skipped and then skips all children. It may work for exec but sonar seems to aggregate/iterate submodules differently.
The next obvious solution indicated by these questions, and to a degree the Sonar documentation itself since the deprecation of sonar.includeModules/sonar.excludeModules in 4.3 is to use Maven's advanced reactor options however that doesn't work for skipping the parent project. Trying to run mvn sonar:sonar -pl one,two,three, or the opposite mvn sonar:sonar -pl !. throws the error:
Maven session does not declare a top level project
Maven does seem to constrain itself to the correct list of modules but sonar itself seems incompatible with the approach and throws the error at the first module.
So now the answer seems to be that I need to run mvn sonar:sonar individually once per module in each module's directory, which is just a bit obnoxious.

How to fix cannot create 'azure-functions-archetype' project issue with maven

I am trying to create Azure Function archetype. When I enter this:
mvn archetype:generate -DarchetypeGroupId=com.microsoft.azure -DarchetypeArtifactId=azure-functions-archetype
in my Maven, it is not creating the archetype and asking to select a number.
After Trying -DinteractiveMode=false
Try something like below:
mvn archetype:generate -DgroupId=com.microsoft.azure -DartifactId=azure-functions-archetype -DinteractiveMode=false
Please refer this link for further reference.
mvn archetype:generate command is used to create a project from an existing template. There are several archetype's defined by many developers and project groups. When you run the command, maven does following things:
Downloads maven-archetype-plugin's latest version.
Lists all archetype's that can be used to create a project from. If you defined an archetype while calling the command, maven jumps to step 4.
By default, maven chooses maven-archetype-quickstart archetype which basically creates a maven Hello World project with source and test classes. If you want to create a simple project, you can just press enter to continue. If you want to create a specific type of application, you should find the archetype matching your needs and enter the number of that archetype, then press enter. E.g. If you want to create a webapp project, you can enter 153 (this is the current number for this archetype, it can change in time.)
Since archetypes are templates and they intend to reflect current best practices, they can evolve in time, thus they have their own versions. Maven will ask you which version of the archetype you want to use. By default, maven chooses latest version for you. so if you agree to use the latest version of an archetype, just press Enter at this step;
Every maven project (and module) has its groupId, artifactId and version. Maven will then ask these to you in three steps. groupId: This is generally unique amongst an organization or a project. artifactId: The artifactId is generally the name that the project is known by. version: This is the last piece of the naming puzzle.(read more)
Finally, maven will ask you the package structure for your code. A best practice is to create your folder structure that reflects the groupId, thus Maven sets this as default but you are free to change this.
After entering these information, Maven will show you all the information you entered and ask you to verify project creation. If you press Y and then enter, voila your project is created with the artifact and settings you chose.
You can also read maven-archetype-plugin's usage site.
Hope it helps.

jenkins hook not working - jenkins bitbucket

Hi i am using jenkins and bitbucket , i want to trigger a build in jenkins when ever i commit any thing to bitbucket repository .
in jenkins
i created a project called test_1
in configure section Build Triggers part i ticked Trigger builds remotely
i added a token TEST_TOKEN
when i type this in my browser url and execute the jenkins build is triggered
http://test.com:8080/job/test_1//build?token=TEST_TOKEN
In bitbucket
i added a jenkins hook
Endpoint : http://test.com:8080/job/test_1//build?token=TEST_TOKEN
Module name - empty
Project name - test_1
Token - empty
then commited some code to bitbucket via git , The jenkins build not running , seems that the trigger is not running . :/ how to solve this problem . please help me . thanks in advance :)
I had the same problem. #fmitchell is correct with his suggestions for these fields.
But it didn't work for me.
I use a normal POST Hook instead where I provide the whole URL:
http://USER_NAME:USER_TOKEN#YOUR.JENKINS.URL.COM:YOUR_PORT/job/YOUR_PROJECT_NAME/build?token=some_token_from_jenkins
eg: http://bob.miller#jenkins.example.com:8080/job/test_1/build?token=TEST_TOKEN
It seems to be that Bitbuckt is missing the last parameter "build" in its created URL, but I can't tell for sure.
------Update------
I found a better solution, where you don't only trigger your build but also be able do build different branches by different Jenkins projects:
Install Bitbucket Plugin at your Jenkins
Add a normal Post as Hook to your Bitbucket repository (Settings -> Hooks) and use following url:
https://YOUR.JENKINS.SERVER:PORT/bitbucket-hook
Configure your Jenkins project as follows:
under build trigger enable Build when a change is pushed to BitBucket
under Source Code Management select GIT; enter your credentials and define Branches to build (like **feature/*)
By this way I have three build projects, one for all features, one for develop and one for release branch.
And best of it, you don't have to ad new hooks for new Jenkins projects.
It should be:
Endpoint : http://test.com:8080/
Module name:
Project name: test_1
Token: TEST_TOKEN

The container 'Maven Dependencies' references non existing library - STS

I'm using win8 previously I had been running Eclipse Juno on my pc but from now on I wanted to start using STS, I am getting the below error as soon as I create a new project. I deleted my .m2 folder and everything related to Eclipse in order to start over from scratch still didn't work, I've ran out of ideas. Any advice???
Can not find the tag library descriptor for "springframework.org/tags" index.jsp /app/src/main/webapp line 6 JSP Problem
The container 'Maven Dependencies' references non existing library 'C:\Users\Pablo.m2\repository\org\springframework\spring-webmvc\3.2.3.RELEASE\spring-webmvc-3.2.3.RELEASE.jar' app Build path Build Path Problem
The project cannot be built until build path errors are resolved app Unknown Java Problem
ArtifactTransferException: Failure to transfer antlr:antlr:jar:2.7.7 from http://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced. Original error: Could not transfer artifact antlr:antlr:jar:2.7.7 from/to central (http://repo.maven.apache.org/maven2): No response received after 60000 pom.xml /app line 1 Maven Dependency Problem
22 more errors like this for each of my dependencies...
Class 'org.springframework.web.servlet.view.InternalResourceViewResolver' not found [config set: app/web-context] mvc-config.xml /app/src/main/webapp/WEB-INF line 16 Spring Beans Problem
So I get you are using Eclipse with the M2E plugin. Try to update your Maven configuration : In the Project Explorer, right-click on the project, Maven -> Update project.
If the problem still remains, try to clean your project: right-click on your pom.xml, Run as -> Maven build (the second one). Enter "clean package" in the Goals fields. Check the Skip Tests box. Click on the Run button.
Edit: For your new problem, you need to add Spring MVC to your pom.xml. Add something like the following:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>4.0.0.RELEASE</version>
</dependency>
Maybe you have to change the version to match the version of your Spring framework. Take a look here:
http://mvnrepository.com/artifact/org.springframework/spring-webmvc
I got the same problem and this is how i solved. :
Right click your Spring MVC project, choose Run As -> Maven install.
Observe the output console to see the installation progress. After
the installation is finished, you can continue to the next step.
Right click your Spring MVC project, choose Maven -> Update Project.
Choose your project and click OK. Wait until update process is
finished.
The error still yet, then do Project->Clean and then be sure you have selected our project directory and then do the follow Project->Build.
Although it's too late , But here is my experience .
Whenever you get your maven project from a source controller or just copying your project from one machine to another , you need to update the dependencies .
For this Right-click on Project on project explorer -> Maven -> Update Project.
Please consider checking the "Force update of snapshot/releases" checkbox.
If you have not your dependencies in m2/repository then you need internet connection to get from the remote maven repository.
In case you have get from the source controller and you have not any unit test , It's probably your test folder does not include in the source controller in the first place , so you don't have those in the new repository.so you need to create those folders manually.
I have had both these cases .
I'm a little late to the party but I'll give my two cents. I just resolved this issue after spending longer than I'd like on it. The above solutions didn't work for me and here's why:
there was a network issue when maven was downloading the required repositories so I actually didn't have the right jars. adding a -U to a maven clean install went and got them for me. So if the above solutions aren't working try this:
Right click on your project -> Choose Run as -> 5 Maven build...
In the Goals field type "clean install -U" and select Run
After that completes right click on your project again and choose Maven -> Update Project and click ok.
Hope it works for you.
I finally found my maven repo mirror is down. I changed to another one, problem solved.
Today I had this same problem with another jar. I tried multiple things people said on Stackoverflow, but nothing worked. Eventually I did this:
Close eclipse and any project-app that is running.
Delete the .m2 folder (Users --> [your_username] --> .m2). It's an invisible folder, make sure you are able to view invisible folders.
Restarted Eclipse (I guess it works in other IDE too) and updated my project.
Now it works again for me. Perhaps this solves the problem for someone else too.
I have solved it using "force update", pressing Alt+F5 as it is mentioned in the following link.
In Eclipse adding to the #Saket Mittal response.
Run As > Maven build...
Set goals clean install and run

Does Maven remember its state so I can easily rerun last command?

I am using Maven multi module project. When I run maven and one of the modules fails I get the error messages and then the following line
After correcting the problems, you can resume the build with the command
mvn <goals> -rf :my.module.name
Does Maven hold any state? Is it possible to run
mvn <goal> `start from where we left off`
The reason I ask is that some of my module names are quite long. I can copy from the cmd prompt but I'd just like a quicker / shorter command. Often saving a couple of seconds may not seem much but over the course of my maven usage it could save me a lot.
The question is
does maven hold state?
if so can I quickly rerun from where I left off?
Thanks
You can use Maven Shell to execute maven goals/phases in a pre-loaded shell environment, significantly reducing the build time.
No, but you could go into the individual modules and build them - this is in essence what maven does, you just need to go through them in the correct order otherwise you might get confusing results (i.e old dependent-module builds etc). The reactor build summary shows you the module build order that maven will run through and is displayed at the start of the build.
In the end though you will always need to do a full build from the parent module in order to build your final artifact. And it's often easiest just to run from the top anyway.
No - at least in my experience, Maven does not hold its state. This is especially important if you are running mvn package. Whereas running mvn package on a multi-module project will work fine (all modules will be able to use the produced artifact of a previous module), if the build is interrupted, resuming from your build mid-way will cause artifact not found errors when referring to previously successfully built modules.
Two ways around this. Rebuild everything, or use mvn install to require maven to install to your local repo (if you are not ready to deploy). In such a case, resuming your build will not fail as it will find the previously built modules in your local repo.
Just as a personal pet peeve, you need to know the module artifact name when using the -rf flag. Maven will show you the display name, which may or may not be the artifact name. -rf requires the artifact name.

Categories