Check java coding styles using jenkins plugin - java

Does anyone know a jenkins plugin for Java that analyses the coding styles and fails the build (not only provide a report) in case there are styles violations?

You can use Findbugs and Checkstyle for the same.
https://plugins.jenkins.io/checkstyle
https://plugins.jenkins.io/findbugs
Jacoco is used to unit test coverage and not really for static analysis.

the solution is to use a plugin of your build tool(like jacoco plugin in your pom for maven build).
And then configure your jenkins pipline to fail if quality is not satisfying

Related

Sonar in bamboo, checkstyle and jacoco local builds

New to Sonar. Am comfortable with checkstyle and jacoco.
What I am exploring is in a a gradle project, give developers ability to run style checks and code coverage reports locally, but then use bamboo to publish reports in sonar.
Is this a viable option ? I can see that jacoco plugin and sonar plugin can be in the same build.gradle and so guessing that jacoco reports can be got from sonar. However am unsure how checkstyle integration works. From what I see, I can add a checkstyle plugin to sonar, but then I will have to define rules in SonarQube. I will like to keep checkstyle configuration locally so developers can run a local check before commiting code.
Bear with me if the questions are naive.
Your goal: enable developers to run the same set of rules locally that are applied in a SonarQube scan.
The means: SonarLint offers a "connected mode" for IntelliJ, Eclipse, and Visual Studio. Assuming you're using the SonarQube Analyzers, they'll get on-the-fly checking as they code using the same rule set locally as is applied in an analysis. If the profile changes on the server, it can be manually re-synchronized in the IDE.
The hitch: to make this work seamlessly, you should look at replacing your Checkstyle rules with the ones offered by the SonarQube Analyzer for Java (i.e. the Java plugin). Almost all of the "valuable" rules from Checkstyle have been replaced in the Java plugin.

Reports from PMD, checkstyle, findbugs

I have a few modules(projects and subprojects) in my application (in Gradle) and i have added plugins: PMD, checkstyle, findbugs. Those plugins create their own reports in their directory (for example: PMD makes directory "PMD" in directory "reports" and put there report). I would like to have a one report for all those plugins. It is possible to do that? And if yes, how do that?
You can't simply configure them to create a shared report together. However, you can use for this purpose either SonarQube or QualityGate. Both tools can execute the above mentioned plugins and they can generate a summarized report as you required.
You probably want take a look at SonarQube. It basically gathers reports of mentioned tools and shows them via nice web app. It can also gather test coverage reports and is free.
Not sure how it can be integrated with Gradle, but we have it integrated with Jenkins. There is also Eclipse plugin I used.
QualityGate (that was mentioned by Csuki) is paid solution.

Can I do these using Code Coverage with Cobertura

I am just looking at the cobertura maven plugin and I wasnt sure if the following is possible
Instrument classes
Run junit tests
Generate Cobertura report without reinstrumenting classes and running tests
I have a multi module maven project and the coverage of the domain module is showing up as 0% even though its been used by every other module
I have tried different combinations of things but the coverage of my domain module always stays at 0%.
People have mentioned writing separate tests for the domain classes but i dont want to do this as you could easily write a tests to test a function that isn't actually being used anywhere within the codebase
Any pointers would be greatly appreciated
In order to do so you would have to execute the maven goals in the correct order so :
cobertura:instrument
test
goalToAskCoberturaToGenerateReport
But then comes the trouble : there is no such goal as cobertura:report, if you look at the documentation and source code of the maven plugin : The goal cobertura:cobertura is the only goal generating the report. I suspect it is as such because of some maven internal limitation.
So in short, given the state of the maven plugin it is not possible.
You might have a chance to manage what you want to achieve by executing cobertura from the command line.
For multi-module maven projects cross-module coverage seems not to be available off-the-shelf with Cobertura.
A solution using a mixture of maven and ant is described byThomas Sundberg:
http://thomassundberg.wordpress.com/2012/02/18/test-coverage-in-a-multi-module-maven-project/
See also this related question:
Maven2 Multiproject Cobertura Reporting Problems During mvn site Build

How to collect statistics about java integration tests

My development environment includes Maven, Failsafe and Spring testing IS (AbstractJUnit4SpringContextTests).
I'm looking for a way to collect statistics about the integration tests run.
Information such as Test duration, process memory, etc...
What is the best way to collect such information with the above configuration (and to integrate with the maven flow).
as far as i recall, the surefire plugin is able to write reports to some directory (which will be used by e.g. jenkins to present results)
There is a maven plugin for Sonar. It is highly configurable, maybe solution to your problem.
The failsafe plugin generates a xml file with the tests result. this can be used, for example by a jenkins plugin.

Hudson style build reports on developer machines/within Eclipse

We use Hudson for our continuous integration which provides us with easy to browse build reports showing compiler warnings, unit test results and coverage (EMMA), pmd, checkstyle and findbugs violations.
Although we each have the relevant plugins installed locally in Eclipse, it often seems easier to simply commit to SVN in order to trigger a Hudson build and generate a build report showing the above info rather than checking with each plugin.
Is there something that developers could install locally (i.e. an Eclipse plugin perhaps) to generate similar reports? Or would it be feasible to somehow use Hudson for this purpose?
You can also install Sonar, which includes all the tools you list (except EMMA which is a plugin). Try it, it's free and open source ! http://sonar.codehaus.org
You Can install hudson locally easily. It is a runnable jar.
Try it. You'll like it.

Categories