3

I have a project I set up with gradle where I'm trying to read user input from the command line using readLine(). However when I run ./gradlew run to run the project, it doesn't actually stop to wait for user input and exits the program after completing. Is it possible to read user input from the command line without having to pass them into arguments when starting the program?

fun main(args: Array<String>) {
    readLine()
}

and here's my build.gradle just in case

plugins {
    id 'java'
    id 'org.jetbrains.kotlin.jvm' version '1.3.41'
    id 'application'
}

group 'project'
version '1.0-SNAPSHOT'

sourceCompatibility = 1.8

repositories {
    mavenCentral()
}

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
    testCompile group: 'junit', name: 'junit', version: '4.12'
    implementation 'com.google.code.gson:gson:2.8.6'
}

compileKotlin {
    kotlinOptions.jvmTarget = "1.8"
}
compileTestKotlin {
    kotlinOptions.jvmTarget = "1.8"
}

application {
    mainClass = 'MainKt'
}
Rafa
  • 3,219
  • 4
  • 38
  • 70

1 Answers1

1

run { standardInput = System.in }

refer to previous answer Console application with Java and gradle

PrasadU
  • 2,154
  • 1
  • 9
  • 10