Gradle: How to write tasks in Kotlin which runs another task?

Viewed 74

I want there to be a lot of test tasks, all of which are based on a "parent task". The parent task should start the client application to be tested and then the one special Call test class. The background is that e.g. I currently call my client manually as follows must "./gradlew client: run --args = 'profile = default_client'" and then start all test classes at once with "./gradlew test" (by the way: these tests connect to the running client via RMI connection.

My approach so far looks like this

open class Testing : DefaultTask() {

    @get:Input
    var profileName = "client"

    @TaskAction
    fun testIt() {
        // 1. run/start the client
        dependsOn(":client:run --args='profile=" + profileName + "'")
        // this won't work: Cannot call Task.dependsOn(Object...) on task ':testing01' after task has started execution.

        // 2. run a SPECIFIC testsuit via gradle
        // ???
    }

}

tasks.register<Testing>("testing01") {
    profileName = "client-tests"
}

Unfortunately I don't know what to do next and how to fix the running of different tasks.

0 Answers
Related