Kotlin Support

If you want to develop your script project in Kotlin, just add the Kotlin JVM and Kotlin SAM-With-Receiver Plugins like in the snippet below:

Application of relevant Kotlin plugins
    plugins {
    // Other plugins...
    id "org.jetbrains.kotlin.jvm" version "2.3.0"
    id "org.jetbrains.kotlin.plugin.sam.with.receiver" version "2.3.0"
    }

Add gradlePluginPortal() to pluginManagement.repositories in settings.gradle as a fallback, especially for Kotlin plugins such as org.jetbrains.kotlin.jvm.

pluginManagement {
    repositories {
        // other repositories...
        gradlePluginPortal()
    }
}

You can then create a class that implements IScriptFactory in src/main/kotlin:

MyKotlinScript.kt in /src/main/kotlin
import com.vector.cfg.automation.scripting.api.IScriptCreationApi
import com.vector.cfg.automation.scripting.api.IScriptFactory
import com.vector.cfg.automation.scripting.api.IScriptTaskTypeApi.DV_APPLICATION

class MyKotlinScript : IScriptFactory {
    override fun createScript(creationApi: IScriptCreationApi) {
        creationApi.scriptTask("TaskName", DV_APPLICATION) {
            code {
                // Task execution code here
            }
        }
    }
}

Remarks:

  • Nullability info on PAI API will be enhanced in the future. This may reveal missing null checks when updating the targeted CFG6 version.

    • You can turn these errors into warnings by adding the following snippet in your build.gradle file:

import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

tasks.withType(KotlinCompile).configureEach {
    it.compilerOptions.freeCompilerArgs.add("-Xnullability-annotations=@org.jspecify.annotations:warn")
}
  • Mixing Groovy and Kotlin source files in a single script project is not natively supported by Gradle. To be able to use your Kotlin classes from your Groovy code, you can add the following snippet in your`build.gradle` file:

tasks.named("compileGroovy", GroovyCompile) {
    it.classpath += files(sourceSets.main.kotlin.classesDirectory)
}

If you want to call Groovy code from your Kotlin code, you need to add the following snippet in your build.gradle file:

tasks.named("compileGroovy") {
    classpath = sourceSets.main.compileClasspath
}

tasks.named("compileKotlin") {
    dependsOn("compileGroovy")
    libraries.from(files(sourceSets.main.groovy.classesDirectory))
}

Note: These snippets are mutually exclusive. You can only use one of them depending on the direction of the calls.