I tried to make a simple “Hello World” kotlin app, with all dependencies stored within it.
Heres the code:
package com.neel.helloworld
fun main(args: Array) {
var str: String = “Hello world”
var name: String = “Neel”
str = str + " from " + name
println(str)
println(“whats up?”)
}
This is my gradle script:
buildscript {
ext.kotlin_version = ‘1.1.51’
repositories {
mavenCentral()
}
dependencies {
classpath “org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version”
}
}
apply plugin: ‘kotlin’
apply plugin: ‘application’
mainClassName = ‘com.neel.helloworld.HelloKt’
defaultTasks ‘run’
repositories {
mavenCentral()
}
dependencies {
compile “org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version”
testCompile ‘junit:junit:4.11’
testCompile “org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version”
}
jar {
manifest {
attributes ‘Main-Class’: ‘com.neel.helloworld.HelloKt’
}
//NEWLINE
from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
}
What i get is an error hen i try to run the resultant jar file which is at /projectroot/build/lib/. The error is:
$java -jar HelloWorld2.jar
Error: Could not find or load main class com.neel.helloworld.HelloKt
I forgot to mention but the name of the file is Hello.kt.
This i tried to build with this command:
$gradle jar
Is my gradle file wrong,and where so? Pls help.