Discover dead simple, improved PIT and JUnit 5 configuration in Gradle (with gradle-pitest-plugin 1.4.7+).
JUnit 5 is undeniably more and more popular nowadays. While there is a dedicated plugin for PIT for JUnit 5 and it has been supported by gradle-pitest-plugin for years, it was required to add a few lines of boilerplate code to achieve that. Recently, I’ve got a question if it could be simplified. I liked it. Challenge accepted :-).
Generic approach with ‘buildscript {}’
First, take a look at the generic approach with the buildscrip {}
code block, which remembers times of Gradle 0.x:
|
|
Just 3 extra lines. Acceptable, however buildscript {}
for plugin configuration is somehow verbose by itself.
Modern approach with ‘plugins {}‘
(with older gradle-pitest-plugin)
The modern variant with plugins {}
should be shorter:
|
|
Unfortunately, the compact syntax of the plugin {}
block is wasted by a need to add an extra dependency pitest-junit5-plugin
used by gradle-pitest-plugin
in runtime in the buildscript {}
block - 10 lines extra. Highly disappointing ;-).
Modern improved approach with ‘plugins {}‘
and gradle-pitest-plugin 1.4.7+
With just released gradle-pitest-plugin
1.4.7 we can forget about all the boilerplate code:
|
|
Just one line junit5PluginVersion = '0.12'
which under the hood adds a pitest-junit5-plugin
dependency in the required versions and activates junit5
as testPlugin
used by PIT. Doesn’t it look nice? :-)
Summary
In this short blog post I presented how the configuration of the PIT, JUnit 5 and Gradle(-pitest-plugin) could be simplified with just a few changes in the plugin itself. All thanks to the question by John Scancella and the idea that sprang into my mind how to implement it in the smart way.
Therefore, I encourage you to report (sensible) ideas for improvements and things that limit you in the projects you use (or even better a pull/merge request after the initial discussion with the maintainer). Maybe it will implemented (accepted) for common good :-).