Apply Checkstyle, Errorprone etc. for all Java modules (FINERACT-1171)

This commit is contained in:
Aleksandar Vidakovic
2020-10-20 03:00:33 +02:00
committed by Aleksandar Vidakovic
parent 4b5a4cb4b0
commit 354acf309e
7 changed files with 338 additions and 197 deletions
+198 -5
View File
@@ -25,6 +25,7 @@ buildscript {
oltuVersion = '1.0.1'
fineractJavaProjects = subprojects.findAll{
[
'fineract-api',
'fineract-provider',
'fineract-client'
].contains(it.name)
@@ -42,15 +43,10 @@ buildscript {
dependencies {
classpath 'com.bmuschko:gradle-cargo-plugin:2.7.1'
classpath 'org.zeroturnaround:gradle-jrebel-plugin:1.1.10'
classpath 'org.springframework.boot:spring-boot-gradle-plugin:2.3.4.RELEASE'
classpath 'org.apache.openjpa:openjpa:3.1.2' // when upgrading, also change OpenJPA version repeated in fineract-provider/build.gradle!
classpath 'com.radcortez.gradle:openjpa-gradle-plugin:3.1.0'
classpath "gradle.plugin.com.github.spotbugs.snom:spotbugs-gradle-plugin:4.5.1"
classpath "gradle.plugin.com.github.andygoossens:gradle-modernizer-plugin:1.3.0"
classpath "gradle.plugin.com.gorylenko.gradle-git-properties:gradle-git-properties:2.2.4"
classpath "net.ltgt.gradle:gradle-errorprone-plugin:1.3.0"
classpath "io.swagger.core.v3:swagger-gradle-plugin:2.1.5"
}
}
@@ -60,6 +56,11 @@ plugins {
id 'org.nosphere.apache.rat' version '0.7.0' apply false
id 'com.github.hierynomus.license' version '0.15.0' apply false
id 'org.openapi.generator' version '4.3.1' apply false
id 'org.zeroturnaround.gradle.jrebel' version '1.1.10' apply false
id 'org.springframework.boot' version '2.3.4.RELEASE' apply false
id 'net.ltgt.errorprone' version '1.3.0' apply false
id 'io.swagger.core.v3.swagger-gradle-plugin' version '2.1.5' apply false
id 'com.gorylenko.gradle-git-properties' version '2.2.4' apply false
}
description = '''\
@@ -80,6 +81,7 @@ allprojects {
apply plugin: 'com.diffplug.spotless'
apply plugin: 'com.github.hierynomus.license'
apply plugin: 'org.nosphere.apache.rat'
apply plugin: 'project-report'
// Configuration for the dependency management plugin
// https://github.com/spring-gradle-plugins/dependency-management-plugin
@@ -341,6 +343,11 @@ configure(project.fineractJavaProjects) {
apply plugin: 'java-library'
apply plugin: 'idea'
apply plugin: 'checkstyle'
apply plugin: 'jacoco'
apply plugin: "net.ltgt.errorprone"
apply plugin: "com.github.spotbugs"
apply plugin: 'com.github.andygoossens.gradle-modernizer-plugin'
/* define the valid syntax level for source files */
sourceCompatibility = JavaVersion.VERSION_11
@@ -456,6 +463,192 @@ configure(project.fineractJavaProjects) {
dependsOn(spotlessApply)
}
}
// If we are running Gradle within Eclipse to enhance classes with OpenJPA,
// set the classes directory to point to Eclipse's default build directory
if (project.hasProperty('env') && project.getProperty('env') == 'eclipse') {
sourceSets.main.java.outputDir = file("$projectDir/bin/main")
}
// Configuration for the Checkstyle plugin
// https://docs.gradle.org/current/userguide/checkstyle_plugin.html
dependencies {
checkstyle 'com.puppycrawl.tools:checkstyle:8.36.2'
checkstyle 'com.github.sevntu-checkstyle:sevntu-checks:1.37.1'
}
// Configuration for JaCoCo code coverage task
// https://www.eclemma.org/jacoco/
jacoco {
toolVersion = jacocoVersion
reportsDir = file("$buildDir/reports/jacoco")
}
jacocoTestReport {
reports {
html.enabled=true
xml.enabled=true
html.destination file("${buildDir}/code-coverage")
}
}
// Configuration for the errorprone plugin
// https://github.com/tbroyer/gradle-errorprone-plugin
dependencies {
errorprone "com.google.errorprone:error_prone_core:2.4.0"
}
tasks.withType(JavaCompile) {
options.errorprone {
disableWarningsInGeneratedCode = true
excludedPaths = ".*/build/.*"
//Todo Remove necessary checks from this list
disable(
"UnusedVariable",
"TypeParameterUnusedInFormals",
"JdkObsolete",
"EmptyBlockTag",
"MissingSummary",
"InvalidParam",
"ReturnFromVoid",
"AlmostJavadoc",
"InvalidBlockTag",
)
//TODO gradually enable these checks
error(
"DefaultCharset",
"RemoveUnusedImports",
"WaitNotInLoop",
"ThreeLetterTimeZoneID",
"VariableNameSameAsType",
"UnnecessaryParentheses",
"MultipleTopLevelClasses",
"MixedMutabilityReturnType",
"MultiVariableDeclaration",
"AssertEqualsArgumentOrderChecker",
"EmptySetMultibindingContributions",
"BigDecimalEquals",
"MixedArrayDimensions",
"PackageLocation",
"UseBinds",
"BadImport",
"IntLongMath",
"FloatCast",
"ReachabilityFenceUsage",
"StreamResourceLeak",
"TruthIncompatibleType",
"ByteBufferBackingArray",
"SameNameButDifferent",
"OrphanedFormatString",
"CatchAndPrintStackTrace",
"ObjectToString",
"StringSplitter",
"AssertThrowsMultipleStatements",
"BoxedPrimitiveConstructor",
"EmptyCatch",
"BoxedPrimitiveEquality",
"SynchronizeOnNonFinalField",
"WildcardImport",
"FutureReturnValueIgnored",
"PrivateConstructorForNoninstantiableModule",
"ClassCanBeStatic",
"ClassNewInstance",
"UnnecessaryStaticImport",
"UnsafeFinalization",
"JodaPlusMinusLong",
"MutableMethodReturnType",
"SwitchDefault",
"VarTypeName",
"ArgumentSelectionDefectChecker",
"CompareToZero",
"InjectOnConstructorOfAbstractClass",
"ImmutableEnumChecker",
"NarrowingCompoundAssignment",
"MissingCasesInEnumSwitch",
"ReferenceEquality",
"UndefinedEquals",
"PublicConstructorForAbstractClass",
"UnescapedEntity",
"ModifyCollectionInEnhancedForLoop",
"NonCanonicalType",
"InvalidInlineTag",
"MutablePublicArray",
"StaticAssignmentInConstructor",
"ProtectedMembersInFinalClass",
"OperatorPrecedence",
"EqualsGetClass",
"EqualsUnsafeCast",
"DoubleBraceInitialization",
"UnnecessaryDefaultInEnumSwitch",
"UnusedNestedClass",
"UnusedMethod",
"ModifiedButNotUsed",
"InconsistentCapitalization",
"MissingOverride",
// "InvalidBlockTag",
// "InconsistentOverloads",
// "MethodCanBeStatic",
// "Var",
// "ConstantField",
// "UnnecessaryDefaultInEnumSwitch",
// "FieldCanBeFinal"
)
}
}
// Configuration for spotbugs plugin
// https://github.com/spotbugs/spotbugs-gradle-plugin
// To generate an HTML report instead of XML
spotbugs {
reportLevel = 'high'
showProgress = true
}
// https://github.com/spotbugs/spotbugs-gradle-plugin/issues/242
spotbugsMain {
reports {
html {
enabled = true
stylesheet = 'fancy-hist.xsl'
}
}
}
spotbugsTest {
reports {
html {
enabled = true
stylesheet = 'fancy-hist.xsl'
}
}
}
spotbugsIntegrationTest {
reports {
html {
enabled = true
stylesheet = 'fancy-hist.xsl'
}
}
}
// Configuration for the modernizer plugin
// https://github.com/andygoossens/gradle-modernizer-plugin
modernizer {
includeTestClasses = true
failOnViolations = true
violationLogLevel="error"
javaVersion = project.targetCompatibility
ignorePackages = []
ignoreGeneratedClasses = true
exclusions = []
exclusionPatterns = [
// To be removed when https://issues.apache.org/jira/browse/FINERACT-826 is fixed
'org/joda/time/.*'
]
}
}
configure(project.fineractPublishProjects) {