diff --git a/src/funcTest/groovy/info/solidsoft/gradle/pitest/functional/Junit5FunctionalSpec.groovy b/src/funcTest/groovy/info/solidsoft/gradle/pitest/functional/Junit5FunctionalSpec.groovy index 7f1985d8..637ed1a5 100644 --- a/src/funcTest/groovy/info/solidsoft/gradle/pitest/functional/Junit5FunctionalSpec.groovy +++ b/src/funcTest/groovy/info/solidsoft/gradle/pitest/functional/Junit5FunctionalSpec.groovy @@ -1,7 +1,9 @@ package info.solidsoft.gradle.pitest.functional +import com.google.common.base.Predicates import groovy.transform.CompileDynamic import nebula.test.functional.ExecutionResult +import nebula.test.functional.GradleRunner import spock.lang.Issue @CompileDynamic @@ -85,4 +87,19 @@ class Junit5FunctionalSpec extends AbstractPitestFunctionalSpec { result2.standardOutput.contains('Reusing configuration cache.') } + @Issue("https://github.com/szpak/gradle-pitest-plugin/issues/333") + void "should not reference project data at execution time (causing InvalidUserCodeException in Gradle 8.1+)"() { + given: + gradleVersion = "8.1" + classpathFilter = Predicates.and(GradleRunner.CLASSPATH_DEFAULT, PitestPluginGradleVersionFunctionalSpec.FILTER_SPOCK_JAR) + and: + copyResources("testProjects/junit5simple", "") + when: + ExecutionResult result = runTasks('pitest', '--configuration-cache', '--rerun-tasks') + then: + !result.standardError.contains('invocation of \'Task.project\' at execution time is unsupported.') + !result.failure + result.wasExecuted('pitest') + } + } diff --git a/src/funcTest/groovy/info/solidsoft/gradle/pitest/functional/PitestPluginGradleVersionFunctionalSpec.groovy b/src/funcTest/groovy/info/solidsoft/gradle/pitest/functional/PitestPluginGradleVersionFunctionalSpec.groovy index c573f084..99c74f78 100644 --- a/src/funcTest/groovy/info/solidsoft/gradle/pitest/functional/PitestPluginGradleVersionFunctionalSpec.groovy +++ b/src/funcTest/groovy/info/solidsoft/gradle/pitest/functional/PitestPluginGradleVersionFunctionalSpec.groovy @@ -3,6 +3,7 @@ package info.solidsoft.gradle.pitest.functional import com.google.common.base.Predicate import com.google.common.base.Predicates import groovy.transform.CompileDynamic +import groovy.transform.PackageScope import groovy.util.logging.Slf4j import info.solidsoft.gradle.pitest.PitestPlugin import nebula.test.functional.ExecutionResult @@ -94,7 +95,9 @@ class PitestPluginGradleVersionFunctionalSpec extends AbstractPitestFunctionalSp //To prevent failure when Spock for Groovy 2.5 is run with Groovy 3.0 delivered with Gradle 7+ //Spock is not needed in this artificial project - just the test classpath leaks to Gradle instance started by Nebula private static final Pattern SPOCK_JAR_PATTERN = Pattern.compile(".*spock-core-2\\..*.jar") - private static final Predicate FILTER_SPOCK_JAR = { URL url -> + @SuppressWarnings('JUnitPublicProperty') + @PackageScope + static final Predicate FILTER_SPOCK_JAR = { URL url -> return !url.toExternalForm().matches(SPOCK_JAR_PATTERN) } as Predicate diff --git a/src/main/groovy/info/solidsoft/gradle/pitest/PitestTask.groovy b/src/main/groovy/info/solidsoft/gradle/pitest/PitestTask.groovy index 311b4ad2..9108fc73 100644 --- a/src/main/groovy/info/solidsoft/gradle/pitest/PitestTask.groovy +++ b/src/main/groovy/info/solidsoft/gradle/pitest/PitestTask.groovy @@ -249,10 +249,14 @@ class PitestTask extends JavaExec { @Optional List overriddenTargetTests //should be Set or SetProperty but it's not supported in Gradle as of 5.6.1 + @Internal + File rootDir + PitestTask() { getMainClass().set("org.pitest.mutationtest.commandline.MutationCoverageReport") ObjectFactory of = project.objects + rootDir = project.rootDir testPlugin = of.property(String) reportDir = of.directoryProperty() @@ -305,19 +309,19 @@ class PitestTask extends JavaExec { @Input String getAdditionalClasspathFilePath() { - return additionalClasspathFile.asFile.get().relativePath(project.rootProject.rootDir) + return additionalClasspathFile.asFile.get().relativePath(rootDir) } @Input @Optional String getHistoryInputLocationPath() { //?. operator doesn't work with Gradle Providers - return historyInputLocation.isPresent() ? historyInputLocation.asFile.get().relativePath(project.rootProject.rootDir) : null + return historyInputLocation.isPresent() ? historyInputLocation.asFile.get().relativePath(rootDir) : null } @Input String getDefaultFileForHistoryDataPath() { - return defaultFileForHistoryData.asFile.get().relativePath(project.rootProject.rootDir) + return defaultFileForHistoryData.asFile.get().relativePath(rootDir) } @Input