szpak / gradle-pitest-plugin

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

How to exclude a module in muli-module project #308

Closed anfruiz closed 2 years ago

anfruiz commented 2 years ago

Hi, I have a multi-module project with module 1, module 2 and module 3.... I want to apply mutationtest only to module 1 and 2 because the module 3 doesn't have test.

I thought that using if (project.name in ['module-without-any-test']) { failWhenNoMutations = false }

it works but not.

Can you help me please?

szpak commented 2 years ago

This will apply the plugin, but do not fail in there are no mutations. However, there might be some other corner cases causing some runtime errors.

Rather than that, you should (not) apply the plugin apply plugin: 'info.solidsoft.pitest' in the requested (sub)project(s).

Something like (pseudo code, please adjust to your needed):

plugins {
    id 'info.solidsoft.pitest' version '1.7.4' apply false
}

subprojects {
    if (project.name in ['module1', 'module2']) {
        apply plugin: 'info.solidsoft.pitest'

        pitest {  ... }
    }

    .... //some other, generic configuration for all the modules
}

In a case of further problems, please paste your actual configuration and received errors.

szpak commented 2 years ago

@anfruiz Have you been able to solve your problem using the aforementioned suggestions?

anfruiz commented 2 years ago

Hi @szpak, sorry I had some troubles with the project... I'll try today this suggestion

anfruiz commented 2 years ago

Thanks, it works

anfruiz commented 2 years ago

Sorry, do you have any example repo with this configuration? @szpak

szpak commented 2 years ago

Hmm, I don't. Maybe you project is publicity available on GitHub?

anfruiz commented 2 years ago

Unfortunately not, but I try to do an example and publish it here

anfruiz commented 2 years ago

Hi @szpak, this is the repo https://github.com/anfruiz/Country

Additionally, I'll try to execute pitestReportAggregate task, if I apply in the (relative) root of the subprojects it fails because in the models module don't exist xml file... so I tried to apply in some module but the pitest directory is empty

szpak commented 2 years ago

I don't see any pitest configuration there. Could you add your (failing) work-in-progress - in a separate branch - and I try to "fix" it.

And write me, which modules should be "mutated" and which not.

anfruiz commented 2 years ago

Ohh sorry I didn't commit the changes. In the main.gradle is the configuration. And all the modules should be mutated, less model module

szpak commented 2 years ago

You were very close - see https://github.com/anfruiz/Country/pull/1

The problem was that you confused the plugins. The main one info.solidsoft.pitest has to be applied in every (sub)project where mutation should happen. The second one is just for aggregate report generation and can/should be applied in the (relative) root project to find any subproject with the main plugin applied and generate the big report from those subreports.

I hope, I was able to describe it in the way that is helpful for you.

Btw, there are two commits. First, fixes the problem with modules. The second one removes the build to use buildscript.classpath dependency. You might want to analyze them separately.

anfruiz commented 2 years ago

Thanks!! @szpak