We use TeamCity for builds with configuration stored in Kotlin DSL. My Kotlin/IntelliJ skills are quite basic with most of my current dev work being done in Javascript/VS Code & C#/Visual Studio. So it could be something very simple that I'm missing.
I have copied an existing TC project into a new project via the Copy Project action in the UI. I can compile the new project's code in IntelliJ successfully at this point.
The original project uses build steps that have been packaged up into its own jar file stored in Artifactory. Looking at the Kotlin script of the new project, the build steps have been translated into script {} blocks.
Original Project BuildType Code
package projects.OriginalProject.buildTypes
import com.mycompany.kotlin.myteam.buildSteps.*
import jetbrains.buildServer.configs.kotlin.v2019_2.BuildType
import jetbrains.buildServer.configs.kotlin.v2019_2.CheckoutMode
import jetbrains.buildServer.configs.kotlin.v2019_2.triggers.vcs
object OriginalProjectBuildAndDeploy : BuildType({
...
params {
...
}
steps {
gitVersion()
...
}
...
}
Copied Project BuildType Code
object CopiedProject_CopiedProjectBuildAndDeploy : BuildType({
...
params {
...
}
vcs {
root(DslContext.settingsRoot)
...
}
steps {
script {
name = "GitVersion"
scriptContent = """
#!/bin/bash
# Fail teamcity build explicitly if a command fails
set -e
/tools/dotnet-gitversion /repo -output buildserver -output json
...
""".trimIndent()
}
...
}
...
})
The script blocks are quite verbose and I'd like to convert them back to using the build steps in the package.
I started with adding the following to pom.xml.
<dependency>
<groupId>com.mycompany.kotlin.myteam</groupId>
<artifactId>gitversion</artifactId>
<version>1.1.3</version>
</dependency>
The challenge I'm having is that when I replaced the script {} block with gitVersion() and add import com.mycompany.kotlin.myteam.buildSteps.* to the top of the file like in the original, the Kotlin compiler doesn't like it and fails with the following error.
Kotlin: Unresolved reference. None of the following candidates is applicable because of receiver type mismatch:
public fun BuildSteps.gitVersion(init: GitVersionLinuxStep.() -> Unit = ...): GitVersionLinuxStep defined in com.mycompany.kotlin.myteam.buildSteps
If I then add import jetbrains.buildServer.configs.kotlin.v2019_2.BuildType to the top of the file, the compiler seems to accept the gitVersion() line but then complains about the root(DslContext.settingsRoot) line with the following error.
Kotlin: None of the following functions can be called with the arguments supplied:
public final fun buildType(bt: BuildType): Unit defined in jetbrains.buildServer.configs.kotlin.Project
public final fun buildType(init: BuildType.() -> Unit): BuildType defined in jetbrains.buildServer.configs.kotlin.Project
I'm a bit confused on these errors and not sure how to fix them.