Published: 05/01/2018
Installing Kotlin on Windows can be difficult, hopefully this guide will help you.
Assumptions
- Windows 10
- Kotlin 1.2.30
- Java 10.0.1
- Gradle 4.7
- Postgres 10.3
Shell? What shell?
If you follow the install process, I’ve been able to use this with the Powershell or Git Bash.
Install proccess
- Install the JDK from Oracle. Get the latest version.
- Install Gradle using
choco install gradle
. - Install kotlin using
choco install kotlin
.
Configure the environment
You’re going to need to set a system environment variable called ‘JAVA_HOME’. Oracle has a doc for this: https://www.java.com/en/download/help/path.xml
Basically go to:
- Control Panel ->
- System ->
- Advanced System Settings ->
- Type your password in ->
- Advanced Tab ->
- Environment Variables ->
- Under “User variables”
- New… ->
- “variable name”: “JAVA_HOME”
- “variable value”: Path to the java folder, mine is “C:\Program Files\Java\jdk-10.0.1”
- Click ok
Now open the terminal, you should be able to run gradle build on the project now
Fixing common errors
com.sun.tools.javac.util.Context
This error occurs when you don’t have JAVA_HOME set or if you set it but haven’t restarted your Windows shell.
e: java.lang.ArrayIndexOutOfBoundsException: 452 :compileKotlin failed
You will get this if the project’s version of Kotlin in the build.gradle file doesn’t match what’s on the system.
Open the file ‘build.gradle’ and ensure that the key ‘ext.kotlin_version’ matches the version above under assumptions.
Gradle won’t start the application
Given the output below:
$ ./gradlew bootRun --stacktrace
FAILURE: Build failed with an exception.
* What went wrong:
Could not determine java version from '10.0.1'.
The fix is to modify the file: ‘gradle/wrapper/gradle-wrapper.properties’, ensure the line distributionUrl
has the correct URL for the version of gradle you’re using. For our project it was 4.7 with ‘https://services.gradle.org/distributions/gradle-4.7-bin.zip’.
Hopefully this guide will help you get your Kotlin project running on Windows. On my machine, it took me about 3 days to figure out, with little helpful step, by step, guide to get Kotlin & Spring Boot running.