Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support JUnit 5 plugin without additional configuration #177

Closed
jscancella opened this issue Feb 23, 2020 · 8 comments
Closed

Support JUnit 5 plugin without additional configuration #177

jscancella opened this issue Feb 23, 2020 · 8 comments
Milestone

Comments

@jscancella
Copy link

@jscancella jscancella commented Feb 23, 2020

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 szpak changed the title Plugin that supports junit without additional configuration Plugin that supports junit5 without additional configuration Feb 24, 2020
@szpak
Copy link
Owner

@szpak szpak commented Feb 24, 2020

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
Copy link
Author

@jscancella jscancella commented Feb 25, 2020

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
Copy link
Owner

@szpak szpak commented Feb 25, 2020

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
Copy link
Author

@jscancella jscancella commented Feb 25, 2020

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

@szpak
Copy link
Owner

@szpak szpak commented Feb 25, 2020

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

@szpak szpak added this to the 1.4.7 milestone Feb 26, 2020
@szpak szpak changed the title Plugin that supports junit5 without additional configuration Support JUnit 5 plugin without additional configuration Feb 27, 2020
@szpak
Copy link
Owner

@szpak szpak commented Feb 27, 2020

Available in just released 1.4.7.

@szpak szpak closed this as completed Feb 27, 2020
@Djaler
Copy link

@Djaler Djaler commented Mar 6, 2020

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

@szpak
Copy link
Owner

@szpak szpak commented Mar 6, 2020

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants