Kotlin and Continuous Integration with TeamCity
We're going to see how to set up TeamCity to build our Kotlin project. For more information and basics of TeamCity please check the Documentation page which contains information about installation, basic configuration, etc.
Kotlin works with different build tools, so if we're using a standard tool such as Ant, Maven or Gradle, the process for setting up a Kotlin project is no different to any other language or library that integrates with these tools. Where there are some minor requirements and differences is when using JBS, which is the internal build system that IntelliJ IDEA uses, which is also supported on TeamCity.
Using a standard build tool
If using Ant, Maven or Gradle, the setup process is straightforward. All that is needed is to define the Build Step. In our case, if using Gradle we'd simply define the required parameters such as the Step Name and Gradle tasks that need executing for the Runner Type.
Since all the dependencies required for Kotlin are defined in the Gradle file, nothing else needs to be configured specifically for Kotlin to run correctly.
If using Ant or Maven, the same configuration applies. The only difference being that the Runner Type would be Ant or Maven respectively.
Using IntelliJ IDEA Build System
If using IntelliJ IDEA build system with TeamCity, we need to make sure that the version of Kotlin being used by IntelliJ IDEA is the same as that that TeamCity runs. This would mean that we need to download the specific version of the Kotlin plugin and install it on TeamCity.
Fortunately, there is a meta-runner already available that takes care of most of the manual work. If not familiar with the concept of TeamCity meta-runners, check the documentation. They are very easy and powerful way to introduce custom Runners without the need to write plugins
Download and install the meta-runner.
The meta-runner for Kotlin is available on GitHub. If using TeamCity 9 or above, we can now simply import that meta-runner from the TeamCity user interface
If using a previous version, refer to the documentation on how to add meta-runners.
Setup Kotlin Compiler Fetching Step
Basically this step is limited to defining the Step Name and the version of Kotlin we need. Tags can be used.
The runner will set the value for the property system.path.macro.KOTLIN.BUNDLED to the correct one based on the path settings from the IntelliJ IDEA project. However this value needs to be defined in TeamCity (and can be set to any value). Therefore we need to define it as a system variable.
Setup Kotlin Compilation Step
The final step is to define the actual compilation of the project, which uses the standard IntelliJ IDEA Runner Type
With that, our project should now build and produce the corresponding artifacts.
Other CI Server
If using a Continuous Integration tool different to TeamCity, as long as it supports any of the build tools, or calling command line tools, compiling Kotlin and automating things as part of a CI process should be possible.