Setup Kotlin using Gradle

While setting up Kotlin using InteliJ is much simpler, then I have observed that many persons search of how to set up Kotlin in Eclipse and gradle. There is nothing complicated in it.

At first take a look at official site:

https://kotlinlang.org/docs/tutorials/getting-started-eclipse.html

There is a plugin available for Eclipse to use Kotlin.

 

Setup Kotlin using Gradle

First of all there is need to add gradle plugin and it’s definition to build.gradle file.

buildscript {
    repositories {
        jcenter()
        mavenCentral()
    }

    dependencies {
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.1.2-2"
    }
}

 

Next, just use this plugin in gradle:

apply plugin: 'kotlin'

 

There also need to be compiler options defined:

compileKotlin {
        kotlinOptions {
            jvmTarget = "1.8"
            apiVersion = proj.ext.kotlinApiVersion
            languageVersion = proj.ext.kotlinApiVersion
        }
    }

 

Dependencies are also very important:

dependencies {
        compile "org.jetbrains.kotlin:kotlin-stdlib-jre8:$kotlin_version"
        compile "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
        
    }

 

Most probably you will want to mix it with java, so it’s better to set up it properly also:

apply plugin: 'java'

sourceCompatibility = 1.8
targetCompatibility = 1.8

compileJava.options.encoding = 'UTF-8'
compileTestJava.options.encoding = 'UTF-8'

 

 

 

Posted in: Simple How To

Tagged as:

Advertisements
Setup Kotlin using Gradle

Do you like Kotlin?

Thank you for the vote!

Leave a Reply

Be the First to Comment!

Leave a Reply

  Subscribe  
Notify of