szpak / gradle-pitest-plugin

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

Task 'pitest' not found in root project 'my-project' (Running pitest with Gradle 7.4) #330

Closed fdaines closed 1 year ago

fdaines commented 1 year ago

Hello there, I'm having some issues trying to run pitest with Gradle, after following your instructions I can't see a task for pitest and having an error when trying to run it.

This is my build.gradle file:

buildscript {
    repositories {
        mavenCentral()
        //Needed only for SNAPSHOT versions
        //maven { url 'https://oss.sonatype.org/content/repositories/snapshots/' }
    }
    dependencies {
        classpath 'info.solidsoft.gradle.pitest:gradle-pitest-plugin:1.9.11'
    }
}

apply plugin: 'info.solidsoft.pitest'

This is the output when I listed the gradle tasks:

my-host » ./gradlew tasks --all                                                                       
Type-safe dependency accessors is an incubating feature.

> Task :tasks

------------------------------------------------------------
Tasks runnable from root project 'my-project'
------------------------------------------------------------

Build Setup tasks
-----------------
init - Initializes a new Gradle build.
wrapper - Generates Gradle wrapper files.

Help tasks
----------
buildEnvironment - Displays all buildscript dependencies declared in root project 'my-project'.
dependencies - Displays all dependencies declared in root project 'my-project'.
dependencyInsight - Displays the insight into a specific dependency in root project 'my-project'.
help - Displays a help message.
javaToolchains - Displays the detected java toolchains.
outgoingVariants - Displays the outgoing variants of root project 'my-project'.
projects - Displays the sub-projects of root project 'my-project'.
properties - Displays the properties of root project 'my-project'.
tasks - Displays the tasks runnable from root project 'my-project'.

Other tasks
-----------
components - Displays the components produced by root project 'my-project'. [deprecated]
dependentComponents - Displays the dependent components of components in root project 'my-project'. [deprecated]
model - Displays the configuration model of root project 'my-project'. [deprecated]
prepareKotlinBuildScriptModel

BUILD SUCCESSFUL in 446ms
1 actionable task: 1 executed

And finally, this is the error when I run the ./gradlew pitest command:

my-host » ./gradlew pitest
Type-safe dependency accessors is an incubating feature.

FAILURE: Build failed with an exception.

* What went wrong:
Task 'pitest' not found in root project 'my-project'.

* Try:
> Run gradlew tasks to get a list of available tasks.
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 447ms

The stacktrace shows this exception:

org.gradle.execution.TaskSelectionException: Task 'pitest' not found in root project 'my-project'.

Environment Information

Gradle Version:

------------------------------------------------------------
Gradle 7.4
------------------------------------------------------------

Build time:   2022-02-08 09:58:38 UTC
Revision:     f0d9291c04b90b59445041eaa75b2ee744162586

Kotlin:       1.5.31
Groovy:       3.0.9
Ant:          Apache Ant(TM) version 1.10.11 compiled on July 10 2021
JVM:          11.0.16.1 (Azul Systems, Inc. 11.0.16.1+1-LTS)
OS:           Mac OS X 13.1 aarch64

Java Version:

openjdk version "11.0.16.1" 2022-07-19 LTS
OpenJDK Runtime Environment Zulu11.58+23-CA (build 11.0.16.1+1-LTS)
OpenJDK 64-Bit Server VM Zulu11.58+23-CA (build 11.0.16.1+1-LTS, mixed mode)
C-Otto commented 1 year ago

Could you try the other approach?

plugins {
    id 'info.solidsoft.pitest' version '1.9.11'
}
fdaines commented 1 year ago

Sure, I tried with this build.gradle content and the output is the same (Task 'pitest' not found in root project 'my-project'.).

plugins {
    id "info.solidsoft.pitest" version "1.9.11"
}
szpak commented 1 year ago

Please make sure to apply also the java plugin in your project (might be before or after the pitest plugin itself). pitest is only for the Java projects and is only effectively applied (activated) then.

fdaines commented 1 year ago

That's right @szpak , with this configuration my project can run pitest with gradle.

buildscript {
    repositories {
        mavenCentral()
        //Needed only for SNAPSHOT versions
        //maven { url 'https://oss.sonatype.org/content/repositories/snapshots/' }
    }
    dependencies {
        classpath 'info.solidsoft.gradle.pitest:gradle-pitest-plugin:1.9.11'
    }
}

apply plugin: 'java-library'
apply plugin: 'info.solidsoft.pitest'

Maybe we can update the documentation with a suggestion to add this plugin if the pitest task is not visible in Gradle.

szpak commented 1 year ago

Maybe we can update the documentation with a suggestion to add this plugin if the pitest task is not visible in Gradle.

Good idea. In fact, the following section about the multimodule projects already has it.

@fdaines Would you mind providing a PR adding the following lines:

id 'java' //or 'java-library' - depending on your needs

and:

apply plugin: 'java' //or 'java-library' - depending on your needs

respectively before the pitest plugin in the Quick start section?

szpak commented 1 year ago

Closing as @fdaines improved documentation in #331. Thanks!