How to add a dependency to Gradle TestKit when using jvm test suite plugin

Hi there. I’m writing my first Gradle plugin and trying now to create some functional tests for it.
I’m using jvm-test-suite plugin and I’ve been trying for the last hours to add the dependency to the gradle-testkit without success. I should be missing something really obvious…

The relevant parts of the build.gradle file are like this:

plugins {
    id 'groovy'
    id 'java-gradle-plugin'
    id 'maven-publish'
}

gradlePlugin {
    plugins {
        cmakePlugin {
            id = 'io.myplugin.gradle.cmake-plugin'
            implementationClass = 'io.myplugin.gradle.cmake.CMakePlugin'
        }
    }
}
...
dependencies {
    implementation 'org.apache.groovy:groovy:4.0.6'
    testImplementation gradleTestKit() // according to the  TestKit documentation
}
...
testing {
    suites {
        integrationTest(JvmTestSuite) {
            useJUnitJupiter('5.9.0')
            dependencies {
                implementation project
            }
        }
        functionalTest(JvmTestSuite) {
            useJUnitJupiter('5.9.0')
            dependencies {
                implementation project
                implementation 'commons-io:commons-io:2.11.0'
            }
        }
    }
}

The integration tests run without issues but when trying to run the functional tests, I get this error:

unable to resolve class org.gradle.testkit.runner.GradleRunner
 @ line 14, column 1.
   import org.gradle.testkit.runner.GradleRunner
   ^

I’ve been reading again and again the documentation of the jvm test suite plugin [1] as well as the one for testkit [2] but haven’t been able to make it work. On the IDE (IntelliJ), the autocompletion for testKit works and I see the jar (gradle-test-kit-7.3.1.jar) on the list of ‘External Libraries’. The test, however, seems to be unable to load this jar. I tried to put the dependency under functionalTest.dependencies, i.e., below ‘commons.io’, so like:

...
 functionalTest(JvmTestSuite) {
            useJUnitJupiter('5.9.0')
            dependencies {
                implementation project
                implementation 'commons-io:commons-io:2.11.0'
                implementation gradleTestKit
            }

but the gradle file became invalid complaining that ‘gradleTestKit’ it’s an unknown property. Same if I added using ’ implementation gradleTestKit()’

Could someone please point out what I’m missing? Thanks!

[1] The JVM Test Suite Plugin
[2] Testing Build Logic with TestKit

Try with implementation project.dependencies.gradleTestKit(), that should work I think.

That fixed the issue, thanks a lot!