ฉันกำลังพยายามสร้างแอปพลิเคชัน HelloWorld อย่างง่ายโดยใช้ kotlin
, gradle
และปลั๊กอิน gradle application
เมื่อฉันรันด้วยการตั้งค่าด้านล่าง ฉันได้รับข้อผิดพลาดต่อไปนี้:
Error: Main method is not static in class com.petarkolaric.helloworld.Main, please define the main method as:
public static void main(String[] args)
My build.gradle
:
group 'helloworld'
version '1.0-SNAPSHOT'
buildscript {
ext.kotlin_version = '1.2.0'
repositories {
mavenCentral()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
apply plugin: 'kotlin'
apply plugin: 'application'
mainClassName = "com.petarkolaric.helloworld.Main"
repositories {
mavenCentral()
}
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
}
compileKotlin {
kotlinOptions.jvmTarget = "1.8"
}
compileTestKotlin {
kotlinOptions.jvmTarget = "1.8"
}
My src/main/kotlin/com/petarkolaric/helloworld/Main.kt
:
package com.petarkolaric.helloworld
class Main {
fun main(args : Array<String>) {
println("Hello, World!")
}
}
ตามโพสต์บล็อกนี้ ฉันควรจะสามารถใช้ ปลั๊กอินแอปพลิเคชันด้วยวิธีนี้
ฉันต้องเปลี่ยนแปลงอะไรบ้างเพื่อให้ปลั๊กอิน application
เรียกใช้ฟังก์ชันหลักของฉันเมื่อฉันเรียกใช้ gradle run