I am newish to Java (haven't done it in probably 7 years). I am using Gradle, with spark-java to create a simple hello world application that just runs this:
import static spark.Spark.*;
fun main(args: Array<String>) {
get("/hello", (req, res) -> "Hello World!");
}
In eclipse I can do this by getting the gradle plugin and starting a new gradle project. But there are also "Kotlin" projects. So you can't start a new gradle project with kotlin.
What I am trying to grok is the fact that with JavaScript and Node I normally do everything by command line. I would like to build this project and run the server from the command line with Gradle, but I am not sure how to do this.
This is my current build.gradle:
// Apply the kotlin plugin to add support for Kotlin
apply plugin: 'kotlin'
buildscript {
ext.kotlin_version = '1.1.2-4'
repositories {
jcenter()
mavenCentral()
}
sourceSets {
main.kotlin.srcDirs += 'src/main/myKotlin'
main.java.srcDirs += 'src/main/myJava'
}
dependencies {
classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.1.2-4'
}
}
// In this section you declare where to find the dependencies of your project
repositories {
// Use 'jcenter' for resolving your dependencies.
// You can declare any Maven/Ivy/file repository here.
jcenter()
}
// In this section you declare the dependencies for your production and test code
dependencies {
// The production code uses the SLF4J logging API at compile time
compile 'com.sparkjava:spark-core:2.3'
// Declare the dependency for your favourite test framework you want to use in your tests.
// TestNG is also supported by the Gradle Test task. Just change the
// testCompile dependency to testCompile 'org.testng:testng:6.8.1' and add
// 'test.useTestNG()' to your build script.
testCompile 'junit:junit:4.12'
}
I run gradle
on the command line and it builds successfully but how would I start the server so I can go to localhost:4567
and see my Hello World
output? What is the general flow I should be following?
To be clear: I am making a conscience decision to use Kotlin instead of Java.