szpak / gradle-pitest-plugin

Gradle plugin for PIT Mutation Testing
http://gradle-pitest-plugin.solidsoft.info/
213 stars 58 forks source link

Support JUnit 5 plugin without additional configuration #177

Closed jscancella closed 4 years ago

jscancella commented 4 years ago

Currently in my build script I have to add

buildscript {
   repositories {
       mavenCentral()
   }
   configurations.maybeCreate("pitest")
   dependencies {
       pitest 'org.pitest:pitest-junit5-plugin:0.10'
   }
}

so that pitest will support my junit5 tests. This is very ugly since everything else I can just define using the more modern plugins configuration. Is there any chance you could release a different plugin that already includes the junit5 dependency so I can remove this code from my build.gradle file?

szpak commented 4 years ago

Thanks for the idea. JUnit 5 becomes more and more popular.

I definitely didh't like the idea to release a different plugin variant to just support JUnit 5. However, even nicer idea sprang to my mind :-).

I added the new junit5PluginVersion configuration property. If set it will add dependency to org.pitest:pitest-junit5-plugin in requested version and also set testPlugin to junit5 (unless set explicitly).

plugins {
    id 'java'
    id 'info.solidsoft.pitest' version '1.4.7-SNAPSHOT'
}

pitest {
    //it adds dependency to org.pitest:pitest-junit5-plugin and also sets "testPlugin" to "junit5"
    junit5PluginVersion = '0.12'
}

You could give the snapshot version a try - unfortunately, with plugins {} it is more challenging :-/

Add to your settings.gradle:

pluginManagement {
    resolutionStrategy {
        eachPlugin {
           if (requested.id.namespace == 'info.solidsoft') {
                useModule('info.solidsoft.gradle.pitest:gradle-pitest-plugin:1.4.7-SNAPSHOT')
            }
        }
    }
    repositories {
//        mavenLocal()  //this is needed only for working with locally installed snapshot
        maven { url 'https://oss.sonatype.org/content/repositories/snapshots/' }
        mavenCentral()
    }
}
jscancella commented 4 years ago

It took some wrangling (those changes to settings.gradle messed up a bunch of other things), but I was finally able to run 'info.solidsoft.pitest' version '1.4.7-SNAPSHOT'

If you released this as version 1.4.7, would I still need to have the configuration in the settings.gradle file?

szpak commented 4 years ago

Not at all. It's just to play with the SNAPSHOT version of the plugin using the plugins {} syntax. Gradle doesn't make it easy :-(.

With a regular version junit5PluginVersion = '0.12' should be the only required change.

jscancella commented 4 years ago

sounds great to me! I look forward to when you release it!

szpak commented 4 years ago

Great. I plan to do that once #155 is fixed.

szpak commented 4 years ago

Available in just released 1.4.7.

Djaler commented 4 years ago

@szpak how can I add other pitest plugins now, like pitest-mutation-testing-elements-plugin?

szpak commented 4 years ago

As usual, mixing the plugin {} and buildscript {} syntax. JUnit 5 is very popular (and it is not built in into PIT itself), so there is a dedicated way. I don't plan to add that configuration for every plugin.

See this section in my blog post for more details: https://blog.solidsoft.pl/2020/02/27/pit-junit-5-and-gradle-with-just-one-extra-line-of-configuration/#modern-approach-with-plugins-br-with-older-gradle-pitest-plugin