How to verify your Kotlin project in a Kotlin way? What linter, code coverage tool and static code analysis plugin to use?! We might know our Java counterparts for this, but what to do when you write your talks in Kotlin?
Kotlin is designed to fully interoperate with Java, mainly provoked by the fact that the JVM version of Kotlin's standard library depends on the Java Class Library. Nevertheless, Kotlin’s standard library has some new tricks which are not supported by Java. Therefore, the Java verification tools might not interpret all the cool new stuff that we’re writing in Kotlin in the right way.
In this talk we’ll go over some plugins (Kover, Ktlint and Detekt) that are specifically designed for the Kotlin language to fully support your Kotlin project!
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
pluginandplay-UtrechtJUG.pptx
1. Plugin and Play
PLUGINS THAT SUPPORT THE FULL SPECTRUM OF KOTLIN FEATURES
15-9-2022
by
Simone
de
Gijt
2. Introduction
Simone de Gijt
2016
2017
2018
2019
2020
2021
…
- Kotlin 1.0 released
- Started working in IT
Google announces that Kotlin is the preferred language of
Android app developers
- Signs contract @ OpenValue
- Starts working with Kotlin
Twitter: @de_gijt
6. Options
JaCoCo
Existing tool
Well-known and widely
recognized format
Has some quirks regarding
Kotlin
Twitter: @de_gijt
IntelliJ IDEA
Available in IntelliJ IDEA
Handles Kotlin well
Only available in IntelliJ
IDEA
9. Advantages Kover
Provided by JetBrains
Fully integrated with the Gradle toolchain and multiplatform projects.
Kotlin Android support without the need to divide into build types and flavours
Customizable filters for instrumented classes
Handles specific Kotlin features
Twitter: @de_gijt
10. Disadvantages
Still in an experimental state
Only available for Gradle (not Maven)
Engine Jacoco doesn’t support Kotlin Directory Structure
Twitter: @de_gijt
14. Advantages
It saves time!
It saves energy
It simplifies your process
Twitter: @de_gijt
15. Plugin options
JLLeitschuh:
Gradle wrapper over
the pinterest project
Adds special tasks
Twitter: @de_gijt
Pinterest:
Static code analysis
tool that is used to
analyse the Kotlin
code for you.
Follows the official
Kotlin code style
GantSign:
Maven wrapper
over the
pinterest
project
19. Options
Sonarqube
Very nice reports that integrate with Gitlab
You get a lot of extra’s..
Community and paid versions
Megalinter
Free
Not Kotlin specific
Twitter: @de_gijt
20. Advantages
Highly configurable rule sets
Specification of quality gates which will break your build
Gradle plugin for code analysis via Gradle builds
SonarQube & IntelliJ integratIons
Third party integrations for Maven, Bazel and Github
Actions (Docker based and Javascript based)
Twitter: @de_gijt
László Kövér is a Hungarian politician and the current speaker of the National Assembly of Hungary.
Kover is pronounced the same as the Dutch word for suitcase.
https://github.com/Kotlin/kotlinx-kover
Source:
Kover – The Code Coverage Plugin https://www.youtube.com/watch?v=jNu5LY9HIbw
Sources:
Kover – The Code Coverage Plugin https://www.youtube.com/watch?v=jNu5LY9HIbw
https://github.com/Kotlin/kotlinx-kover
https://kotlinlang.org/docs/multiplatform.html
Demo:
Start with JaCoCo
Show you can not see the class in the report (because of directory structure)
Show inline function is not ”covered”
Show IntelliJ
Add Kover to the plugins
Run report
Open as HTML and show that you now can see the class-file including the coverage of the inline function
Show that test classes are also tested by default
Unmute integrationtests -> no additional config like with jacoco
Standard: test is without Kover -> add config
Show that you can exclude classes from Kover (both extension + report)
Show kover config
koverVerify
Maybe subprojects (merged reports)
Sources
https://blog.mindorks.com/code-formatting-in-kotlin-using-ktlint
https://github.com/JLLeitschuh/ktlint-gradle
https://github.com/pinterest/ktlint
https://github.com/gantsign/ktlint-maven-plugin
https://megalinter.github.io/latest/installation/
JLLeitschuh: The plugin can be applied to any project, but only activates if that project has the kotlin plugin applied
Check tasks support change files to be checked incrementally. On the first run, the task will check all files in the source set, on subsequent runs it will check only added/modified files.
IntelliJ IDEA: recommended to work with the ktlint install from brew
Demo:
Basic project without a lint; show format-error in service -> build -> no issues
Add ktlint (normal plugin) to project: show all new tasks
Show that if you only want intellij idea tasks you can add -idea in the plugin: build, after ktlintCheck
2 options:
Create baseline: ktlintGenerateBaseline
Format via: ktlintFormat / option+command+l
Git integration:
addKtlintCheckGitPreCommitHook
addKtlintFormatGitPreCommitHook
Add plugin Nick Badal
Actions on save
Additional config file:
Without editorconfig file or ktlint plugin the rules of preferences are applied (KOTLIN)
You can overwrite this by the editorconfig file (no extra config needed)
Source:
https://medium.com/@vanniktech/writing-your-first-ktlint-rule-5a1707f4ca5b
ComplexCondition
Demo:
Basic project without a lint; show format-error in service -> build -> no issues
Add ktlint (normal plugin) to project: show all new tasks
Show that if you only want intellij idea tasks you can add -idea in the plugin: build, after ktlintCheck
2 options:
Create baseline: ktlintGenerateBaseline
Format via: ktlintFormat / option+command+l
Git integration:
addKtlintCheckGitPreCommitHook
addKtlintFormatGitPreCommitHook
Add plugin Nick Badal
Actions on save
Additional config file:
Without editorconfig file or ktlint plugin the rules of preferences are applied (KOTLIN)
You can overwrite this by the editorconfig file (no extra config needed)
Source:
https://medium.com/@vanniktech/writing-your-first-ktlint-rule-5a1707f4ca5b