A Gradle plugin that enables and configures a number of code style and quality plugins for java development.
This plugin is a low-friction way of improving you code quality:
- enables a range of plugins with no clutter added to the build file (assuming the convention configurations are agreeable)
- configured entirely via entries in
gradle.properties
, so disabling/removing the plugin does not break the build file
Add plugin activation to the build file header (substitute the relevant version):
plugins {
...
id 'dk.mada.style' version '1.n.n'
}
And make sure the plugin can be fetched from MavenCentral:
pluginManagement {
repositories {
gradlePluginPortal()
mavenCentral()
}
}
For null-checker annotations, you should add the JSpecify dependency:
compileOnly "org.jspecify:jspecify:1.0.0"
Note that the annotations are not as easy to remove as the plugin (since they will be spread out over various source files).
Just remove the apply-line in build.gradle
to disable or remove all plugin activity.
Remove all the dk.mada.style.
-prefixed entries in gradle.properties
if you want to the remove the plugin for good.
- Checkstyle: Style checking framework
- ErrorProne: Error checking framework
- NullAway: ErrorProne plugin
- Sonar: SonarScanner
- Spotless: Enforces the eclipse-base dk.mada code formatter
Properties in gradle.properties
allow configuration of the sub-plugins.
Using properties (instead of DSL) allows the plugin (and sub-plugins) to be removed without breaking the build. (Assuming that you do not add sub-plugin DSL configuration elements to the build file.)
The options are (shows here with their default value).
Checkstyle
By default uses this configuration and these suppressions
dk.mada.style.checkstyle.enabled = true
Boolean flag allowing the checkstyle checker to be disableddk.mada.style.checkstyle.includes =
Comma-separated Ant-style include patterns for files to checkdk.mada.style.checkstyle.excludes =
Comma-separated Ant-style exclude patterns for files to not checkdk.mada.style.checkstyle.ignore-generated-source = false
Boolean flag to control scanning of test source filesdk.mada.style.checkstyle.ignore-test-source = false
Boolean flag to control scanning of generated source filesdk.mada.style.checkstyle.config-path = null
Optional path to an alternative checkstyle configuration file
This can be a URL; the content will be downloaded and cached (so if you want to update the content, you must change the URL) Note that the configDir is set to the folder where the mada config and suppressions files are stored.
The suppressions file is hardwired for now, matching files dk/.*/(accept|fixture|unit)/.*java
and checks (Javadoc|LineLength|MagicNumber)
.
ErrorProne
dk.mada.style.errorprone.enabled = true
Boolean flag allowing the error prone checker to be disableddk.mada.style.errorprone.ignore-generated-source = false
Boolean flag to control scanning of generated source files
Note: works poorly with Immutable generated sources (as they cannot be referenced from the main sources when enabled)dk.mada.style.errorprone.ignore-test-source = false
Boolean flag to control scanning of test source filesdk.mada.style.errorprone.excluded-paths-regexp =
Optional regular expression used to exclude files from scanning
Formatter (Spotless)
By default uses this configuration
dk.mada.style.formatter.enabled = true
Boolean flag allowing the formatter to be disableddk.mada.style.formatter.include = src/main/java/**/*.java, src/test/java/**/*.java
Comma-separated Ant-style include patterns for files to formatdk.mada.style.formatter.exclude =
Comma-separated Ant-style exclude patterns for files to not formatdk.mada.style.formatter.eclipse-config-path = null
Optional path to an alternative eclipse formatter configuration file This can be a URL; the content will be downloaded and cached (so if you want to update the content, you must change the URL)dk.mada.style.formatter.eclipse-432-p2-url = null
Optional URL to a P2 update repository containing Eclipse 4.32 (aka 2024.06) plugins.
Null-checker
Note that this is a plugin to ErrorProne, so is also affected by errorprone configuration keys.
dk.mada.style.null-checker.enabled = true
Boolean flag allowing the null-checker to be disableddk.mada.style.null-checker.include-packages = dk
Comma-separated list of packages to be scanned (will include sub-packages)dk.mada.style.null-checker.exclude-packages =
Comma-separated list of packages to be excluded from scanningdk.mada.style.null-checker.exclude-field-annotations = javafx.fxml.FXML, org.junit.jupiter.api.io.TempDir
Comma-separated list of classes that are assumed to inject (non-null) value into fields
Sonar
All properties (except enabled
) are simply passed on to the Sonar plugin, thus allowing configuration without DSL.
dk.mada.style.sonar.enabled = true
Boolean flag allowing sonar to be disableddk.mada.style.sonar.host.url = https://sonarcloud.io
The sonar cloud host addressdk.mada.style.sonar.sourceEncoding = UTF-8
The source encoding
For testing snapshot builds in other projects:
$ ./gradlew -t publishToMavenLocal -Pversion=0.0.1