configured pmd and spotbugs

This commit is contained in:
Konrad Neitzel 2022-07-19 22:02:27 +02:00
parent 370fce41ac
commit e3db056b08
4 changed files with 85 additions and 53 deletions

View File

@ -4,3 +4,4 @@ Example Maven Project for a JavaFX Application.
Maven modules are configured so that even Images are build (including JPackage app-image).
Project includes PMD and spotbugs!

0
mvnw vendored Normal file → Executable file
View File

View File

@ -1,65 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<ruleset name="Custom Java Ruleset"
xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 http://pmd.sourceforge.net/ruleset_2_0_0.xsd">
xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 http://pmd.sourceforge.net/ruleset_2_0_0.xsd">
<description>
Custom ruleset for Java
</description>
<rule ref="category/java/bestpractices.xml/AvoidUsingHardCodedIP" />
<rule ref="category/java/bestpractices.xml/CheckResultSet" />
<rule ref="category/java/bestpractices.xml/UnusedFormalParameter" />
<rule ref="category/java/bestpractices.xml/UnusedLocalVariable" />
<rule ref="category/java/bestpractices.xml/UnusedPrivateField" />
<rule ref="category/java/bestpractices.xml/UnusedPrivateMethod" />
<rule ref="category/java/bestpractices.xml">
<!-- System.println is ok in simple Console App -->
<exclude name="SystemPrintln" />
</rule>
<rule ref="category/java/codestyle.xml/ExtendsObject" />
<rule ref="category/java/codestyle.xml/ForLoopShouldBeWhileLoop" />
<rule ref="category/java/codestyle.xml/TooManyStaticImports" />
<rule ref="category/java/codestyle.xml/UnnecessaryFullyQualifiedName" />
<rule ref="category/java/codestyle.xml/UnnecessaryModifier" />
<rule ref="category/java/codestyle.xml/UnnecessaryReturn" />
<rule ref="category/java/codestyle.xml/UselessParentheses" />
<rule ref="category/java/codestyle.xml/UselessQualifiedThis" />
<rule ref="category/java/codestyle.xml" />
<rule ref="category/java/design.xml/CollapsibleIfStatements" />
<rule ref="category/java/design.xml/SimplifiedTernary" />
<rule ref="category/java/design.xml/UselessOverridingMethod" />
<rule ref="category/java/design.xml" />
<rule ref="category/java/errorprone.xml/AvoidBranchingStatementAsLastInLoop" />
<rule ref="category/java/errorprone.xml/AvoidDecimalLiteralsInBigDecimalConstructor" />
<rule ref="category/java/errorprone.xml/AvoidMultipleUnaryOperators" />
<rule ref="category/java/errorprone.xml/AvoidUsingOctalValues" />
<rule ref="category/java/errorprone.xml/BrokenNullCheck" />
<rule ref="category/java/errorprone.xml/CheckSkipResult" />
<rule ref="category/java/errorprone.xml/ClassCastExceptionWithToArray" />
<rule ref="category/java/errorprone.xml/DontUseFloatTypeForLoopIndices" />
<rule ref="category/java/errorprone.xml/EmptyCatchBlock" />
<rule ref="category/java/errorprone.xml/EmptyFinallyBlock" />
<rule ref="category/java/errorprone.xml/EmptyIfStmt" />
<rule ref="category/java/errorprone.xml/EmptyInitializer" />
<rule ref="category/java/errorprone.xml/EmptyStatementBlock" />
<rule ref="category/java/errorprone.xml/EmptyStatementNotInLoop" />
<rule ref="category/java/errorprone.xml/EmptySwitchStatements" />
<rule ref="category/java/errorprone.xml/EmptySynchronizedBlock" />
<rule ref="category/java/errorprone.xml/EmptyTryBlock" />
<rule ref="category/java/errorprone.xml/EmptyWhileStmt" />
<rule ref="category/java/errorprone.xml/JumbledIncrementer" />
<rule ref="category/java/errorprone.xml/MisplacedNullCheck" />
<rule ref="category/java/errorprone.xml/OverrideBothEqualsAndHashcode" />
<rule ref="category/java/errorprone.xml/ReturnFromFinallyBlock" />
<rule ref="category/java/errorprone.xml/UnconditionalIfStatement" />
<rule ref="category/java/errorprone.xml/UnnecessaryConversionTemporary" />
<rule ref="category/java/errorprone.xml/UnusedNullCheckInEquals" />
<rule ref="category/java/errorprone.xml/UselessOperationOnImmutable" />
<rule ref="category/java/documentation.xml" />
<rule ref="category/java/multithreading.xml/AvoidThreadGroup" />
<rule ref="category/java/multithreading.xml/DontCallThreadRun" />
<rule ref="category/java/multithreading.xml/DoubleCheckedLocking" />
<rule ref="category/java/errorprone.xml" />
<rule ref="category/java/performance.xml/BigIntegerInstantiation" />
<rule ref="category/java/multithreading.xml" />
<rule ref="category/java/performance.xml" />
<rule ref="category/java/security.xml" />
</ruleset>

71
pom.xml
View File

@ -20,21 +20,26 @@
<main.class>de.kneitzel.JavaFXApp</main.class>
<main.module>FXAppModule</main.module>
<java.version>17</java.version>
<required.maven.version>3.6.3</required.maven.version>
<!-- Dependency versions -->
<junit.version>5.8.2</junit.version>
<javafx.version>17.0.2</javafx.version>
<lombok.version>1.18.20</lombok.version>
<jetbrains.annotations.version>23.0.0</jetbrains.annotations.version>
<!-- Plugin dependencies -->
<maven.compiler.plugin>3.8.1</maven.compiler.plugin>
<maven.dependency.plugin>3.1.2</maven.dependency.plugin>
<maven.enforcer.plugin>3.1.0</maven.enforcer.plugin>
<maven.surfire.plugin>3.0.0-M5</maven.surfire.plugin>
<moditect.maven.plugin>1.0.0.RC1</moditect.maven.plugin>
<jpackage.maven.plugin>0.1.2</jpackage.maven.plugin>
<maven.pmd.version>3.14.0</maven.pmd.version>
<pmd.version>6.38.0</pmd.version>
<maven.pmd.version>3.16.0</maven.pmd.version>
<pmd.version>6.47.0</pmd.version>
<codehaus.version.plugin>2.8.1</codehaus.version.plugin>
<spotbugs.maven.plugin>4.7.1.0</spotbugs.maven.plugin>
<spotbugs.version>4.7.1</spotbugs.version>
<!-- other properties -->
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
@ -67,6 +72,14 @@
<scope>provided</scope>
</dependency>
<!-- Dependency used for @NotNull / @Nullable -->
<dependency>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
<version>${jetbrains.annotations.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
@ -77,6 +90,27 @@
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>${maven.enforcer.plugin}</version>
<executions>
<execution>
<id>enforce-versions</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<requireMavenVersion>
<version>${required.maven.version}</version>
</requireMavenVersion>
</rules>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
@ -205,6 +239,32 @@
</executions>
</plugin>
<plugin>
<groupId>com.github.spotbugs</groupId>
<artifactId>spotbugs-maven-plugin</artifactId>
<version>${spotbugs.maven.plugin}</version>
<dependencies>
<!-- overwrite dependency on spotbugs if you want to specify the version of spotbugs -->
<dependency>
<groupId>com.github.spotbugs</groupId>
<artifactId>spotbugs</artifactId>
<version>${spotbugs.version}</version>
</dependency>
</dependencies>
<executions>
<execution>
<phase>prepare-package</phase>
<goals>
<!-- pmd does not stop build when violations are found -->
<goal>spotbugs</goal>
<!-- check stops the build when violations are found -->
<!-- <goal>check</goal> -->
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
@ -241,8 +301,13 @@
</configuration>
<executions>
<execution>
<phase>prepare-package</phase>
<goals>
<goal>check</goal>
<!-- pmd does not stop build when violations are found -->
<goal>pmd</goal>
<!-- check stops the build when violations are found -->
<!-- <goal>check</goal> -->
</goals>
</execution>
</executions>