Getting Started

In build.gradle define the versions of Gradle that needs to be tested:

gradleTestSets {
   testSets {
     main {
       versions '6.1', '7.3.3', '8.11.1'
     }
   }

}

Create a folder called src/gradleTest. Beneath that add a folder - call it 'myExample` for now. Within that create a normal Gradle project i.e. drop a build.gradle file and fill it out with the kind of syntax that a person will use to run your plugin. Finally add a custom task called runGradleTest and make it depend on some task that your plugin provides.

For example here is one example from GradleTest’s test suite of how itself is being tested.

gradleTestSets {
    testSets {
        main {
            versions '7.3.3', '8.9'
            expectedFailures 'expectedBuildFailure'
            useCustomManifest()
        }
    }
}

tasks.register('runGradleTest') {
    dependsOn 'gradleTest'
}

Using multiple build files

You can use multiple build files for a single project layout. For you can add both build.gradle and a build.gradle.kts file. GradleTest will generate two tests and use the two alternatively.

You can even add more build files, by using naming convention staged.<NAME>.build.gradle(.kts). GradleTest will generate an additional test for each staged file and place the appropriate build.gradle or build.gradle.kts in that generate project directory.

Settings file

You should add either a settings.gradle or settings.gradle.kts file. If you don’t GradleTest will place a blank settings.gradle in the target project directory.

You should only use one of the two DSLs for the settings file. If you add a settings file in both Groovy & Kotlin, GradleTest will use the Groovy version.