using Kotlin with Gradle

Viewed 2944

I'm new to Kotlin and Gradle, and tried to follow these steps, so I got the following 2 files:

after running gradle init I changed the build.gradle to be:

// set up the kotlin-gradle plugin
buildscript {
    ext.kotlin_version = '1.1.2-2'

    repositories {
        mavenCentral()
    }

    dependencies {
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

// apply the kotlin-gradle plugin
apply plugin: "kotlin"
apply plugin: 'application'

mainClassName = "hello.main"

// add kotlin-stdlib dependencies.
repositories {
    mavenCentral()
}

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

Hello.kt:

package hello   

fun main(args: Array<String>) {   
   println("Hello World!")        
}

Then I run the gradle build and got the build\classes\main\hello\HelloKt.class

my question is: Why the file generated is .class not .jar and how to get the .jar file and how to run it, I tried running the generated file using kotlin -classpath HelloKt.class main but got an error error: could not find or load main class hello.main

2 Answers
Related