Sonar does almost same checks. But sonar does not fail builds. Usually, sonar checks are triggered and inspected after code is pushed to remote repository throgh a CDI pipeline. At that point, code is already submitted to upstream.
Add this project as a parent to your parent pom.
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.bahadirakin</groupId>
<artifactId>grand-parent-pom</artifactId>
<version>1.1</version>
</parent>
...
</project>
After adding this, on your next build all the checks are automaticaly run.
Jacoco maven plugin calculates code coverage. grand-parent-pom configures Jacoco maven plugin to force branch and line coverage for each class. Users can configure minimum code coverages.
- rule.branch.coverage: Each class' branch coverage. Default is
0.50
- rule.line.coverage: Each class' line coverage. Default is
0.50
These properties can be configured on child classes. For example, to set line and branch coverage to 0.60
:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.bahadirakin</groupId>
<artifactId>grand-parent-pom</artifactId>
<version>1.0</version>
</parent>
...
<properties>
...
<rule.branch.coverage>0.60</rule.branch.coverage>
<rule.line.coverage>0.60</rule.line.coverage>
...
</properties>
...
</project>
To disable test coverage chekcs, skip.jacoco.check
property can be used. This property can be used both in command line and in your pom.xml
.
$ mvn clean install $skip.jacoco.check
Checkstyle checks general code structure. All the rules are embedded to grand-parent-pom xml. Checkstyle rules are determined using:
Users can suppress some of the checks during development. For example, to suppress VisibilityModifier
check you can use comments like this.
@Component
public class SchedulerController {
//CHECKSTYLE.OFF: VisibilityModifier - Because bla bla bla
@Autowired
Scheduler scheduler;
//CHECKSTYLE.ON: VisibilityModifier
...
}
To disable CheckStyle chekcs, skip.checkstyle.check
property can be used. This property can be used both in command line and in your pom.xml
.
$ mvn clean install $skip.checkstyle.check
Findbugs checks common patterns that leads bugs.
To suppress rules, grand-parent-pom provides additional annotations for findbugs. Here is an example for suppressing SE_NO_SERIALVERSIONID
@SuppressFBWarnings(value = "SE_NO_SERIALVERSIONID",justification = "because bla bla bla....")
public class MyClass implements Serializable {
...
}
To disable Findbugs chekcs, skip.findbugs.check
property can be used. This property can be used both in command line and in your pom.xml
.
$ mvn clean install $skip.findbugs.check