All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.danilopianini.multijvmtesting.TestOnSpecificJvmVersion.kt Maven / Gradle / Ivy

Go to download

This gradle plugin runs the test suit with multiple versions of the Java Virtual Machine

There is a newer version: 1.3.2
Show newest version
package org.danilopianini.multijvmtesting

import org.gradle.api.tasks.Internal
import org.gradle.api.tasks.testing.Test
import org.gradle.jvm.toolchain.JavaLanguageVersion
import org.gradle.jvm.toolchain.JavaToolchainService
import org.gradle.kotlin.dsl.getByType
import javax.inject.Inject

/**
 * A special [Test] task configured to run the tests using a specific [jvmVersion].
 */
abstract class TestOnSpecificJvmVersion @Inject constructor(@Internal val jvmVersion: Int) : Test() {

    init {
        group = TASK_GROUP
        description = makeTaskDescription(jvmVersion)
        val javaToolchains = project.extensions.getByType(JavaToolchainService::class)
        val launcher = javaToolchains.launcherFor {
            it.languageVersion.set(JavaLanguageVersion.of(jvmVersion))
        }
        javaLauncher.set(launcher)
    }

    internal companion object {

        internal const val TASK_GROUP = "Verification"

        internal fun makeTaskDescription(version: Int) =
            "Runs the unit tests using a Java Virtual Machine (JVM) version $version."
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy