Autofix maven checkstyle errors - maven

I'm using IntelliJ IDEA along with google checks rules to validate code quality.
Also, I have CheckStyle IDEA plugin installed in my IDE.
This plugin identifies all the checkstyle issues.
But I'm looking for an autofix solution for these errors (at least for indentation issues and import order). Is there any plugin available for that, or can I configure Checkstyle IDEA to do the same?

Related

Gradle equivalent for Maven Java formatter that uses com.googlecode.maven-java-formatter-plugin

I'm switching a large project from Maven to Gradle. Existing Maven project uses com.googlecode.maven-java-formatter-plugin to format the Java code. Looked for the equivalent in Gradle. Found https://plugins.gradle.org/plugin/com.github.sherter.google-java-format, but it spewed a bunch of errors out, was really slow, and didn't generate the same output as the Maven plugin.
Also looked here: https://github.com/google/google-java-format - no help.
Is there a Gradle plugin which will give me same result as the Maven plugin?
There is this other Gradle plugin, which uses the Eclipse formatter. Maybe you can tweak it to achieve the same results as with the maven plugin you mentioned (I'm not using this plugin myself).
Note that it is an explicit non-goal of google-java-format and the corresponding Gradle plugin to be configurable. If you are not happy with the formatting style then this tool is probably not appropriate for you.
(if you have technical problems with my Gradle plugin, feel free to provide more details or open a ticket on Github)

Analyze Maven pom with SonarQube

Can I analyze pom files correctness using Sonar? (like the maven enforcer plugin rules)
The short answer is no. The slightly longer answer is maybe. There is no plugin listed on the office plugins page with this functionality, but it's possible to write a plugin that could run some rules on a maven project and report the issues as like with any other metric...

The Issues Report Plugin does not retrieve metrics

I have a problem when I run the Issues Report Plugin on the multi-module project. I noted that the documentation indicated that the plugin is incompatible with this kind of project.
Nevertheless, I tried to run a sonar-runner dry run on one of the modules using its projectKey and projectName (retrieved from the widget Description). Unfortunately, the plugin has not retrieved metrics previously analyzed for this module. All anomalies are marked as new.
Is there a way to ensure I get the right values?
The dry run mode for SonarQube analyses on multi-module projects suffers from limitations, which are all fixed in the upcoming 3.6.1 version of SonarQube.
See the following ticket: https://jira.codehaus.org/browse/SONAR-4265
And just to be clear: the Issues Report Plugin does not export measures of metrics, it only exports issues.

intellij/maven (/checkstyle)

Sitting in intellij community edition 11, I'd like to run checkstyle with exactly the options that maven will run it with. In fact, I'd be happy to just run a maven build of the module and get any checkstyle (or PMD (or whatever)) errors. I'm not seeing how to do this.
You can follow the steps in this documentation, create a new configuration for a maven goal and specify checkstyle:checkstyle. This can then be run from Run menu.
There could be other (better) ways, but this is based on my limited (first-time) experience with IDEA.

Jenkins Sonar plugin throws duplicate source file error during analysis

I have set up Sonar with MySQL Database. My project is a multi module eclipse project, which means it has multiple plugins.
I have set up a Jenkins build with Maven to build this project and also installed Jenkins Sonar plugin to analyse the code with sonar.
All the configurations seem to be correct. However, when sonar tries to analyse this project after the build, it complains of duplicate source code and the build fails.
Each eclipse plugin has Activator.java class and Sonar complains that this is duplicate. I have excluded this class from analysis, but Sonar complains of classes in a particular plugin that is added as a dependency to lot other plugins.
Incomplete analysis of the code leads to other issues in Sonar for this project. like, even though the project is visible in the Sonar dashboard, it asks for authentication again on clicking the project, even though I am logged in as admin.
Any inputs on pointing me to the right direction would be very helpful.
Please let me know if any additional inputs are necessary to better understand my problem.
IMO, the best example you can follow is our Sonar Eclipse project: https://github.com/SonarSource/sonar-eclipse. This is also a multi-module Eclipse project.
In this example, you want to have a look at the parent module (https://github.com/SonarSource/sonar-eclipse/tree/master/org.sonar.ide.eclipse.parent) which goal is only to define the parent POM. Almost everything happens there.
I guess that you should find your way thanks to this.
I was able to fix this issue by removing the test tag in the parent pom.xml. This was somehow causing sonar to throw the duplicate source error. It was a tedious task to figure out the root cause and I had to reconstruct pom.xml from scratch, adding section by section.
Thanks to all for the help.

Resources