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

Setting up pitest with JUnit5 without keeping any versions in build.gradle #363

Open
jan-gebauer opened this issue Jul 12, 2024 · 3 comments

Comments

@jan-gebauer
Copy link

Hi,

our usecase is that we would like to keep all version numbers out of our build.gradle files. Normally, we do this by using init.d in our .gradle folder. This worked well for version of the plugin itself but not so much for the junit5PluginVersion. It also works reasonably well for the other settings, such as mutationThreshold.

In init.d we have a file called pitest.init.gradle that looks like this

allprojects {
  afterEvaluate { project -> 
    project.plugins.withId("info.soildsoft.pitest") {
      junit5PluginVersion = '1.2.1'
      mutationThreshold = 65
      // other settings
    }
  }
}

The pitest version is set elsewhere. The presented code does not work and it is as if we didn't set the junit5PluginVersion at all. Are we doing something wrong? Is there a way to do this?

I noticed that there was a discussion about it but nothing seemed conclusive.

@szpak
Copy link
Owner

szpak commented Jul 12, 2024

Maybe instead of 1.2.1 you could refer to some dynamic global variable ext.xxx which should be set before the afterEvaluate closure is effectively called?

I noticed that there was a discussion about it but nothing seemed conclusive.

Could you paste a link to it?

@szpak
Copy link
Owner

szpak commented Jul 12, 2024

You could also try to approach this case from the other side and mimic the helper logic in your init.d, effectively adding org.pitest:pitest-junit5-plugin on your own (in the pitest configuration).

private void addPitJUnit5PluginIfRequested(Configuration pitestConfiguration) {
pitestConfiguration.withDependencies { dependencies ->
if (extension.junit5PluginVersion.isPresent()) {
if (extension.testPlugin.isPresent() && extension.testPlugin.get() != PITEST_JUNIT5_PLUGIN_NAME) {
log.warn("Specified 'junit5PluginVersion', but other plugin is configured in 'testPlugin' for PIT: '${extension.testPlugin.get()}'")
}
String junit5PluginDependencyAsString = "org.pitest:pitest-junit5-plugin:${extension.junit5PluginVersion.get()}"
log.info("Adding JUnit 5 plugin for PIT as dependency: ${junit5PluginDependencyAsString}")
dependencies.add(project.dependencies.create(junit5PluginDependencyAsString))
}
}

@jan-gebauer
Copy link
Author

Hi, we ended up going with setting the version through the ext variable, thank you!

The discussion is here, I believe: #334

This issue can be closed, by the way.

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

2 participants