Console Application with Java and Gradle

Console application with Java and gradle

By default, the system.in of your Gradle build is not wired up with the system.in of the run (JavaExec) task. You can do the following:

build.gradle (Groovy syntax):

run {
standardInput = System.in
}

build.gradle.kts (Kotlin DSL syntax):

tasks.named<JavaExec>("run") {
standardInput = System.`in`
}

Issues running Gradle program from terminal

Two actions can help you to get this resolved;

  1. Add below task in your build.gradle.
run{
standardInput = System.in
}

  1. Though this enables your command-line to accept input now. It still provides some ambiguity in run and hence executing below command can help you to get your exact expected output.

gradle --console=plain run

Detailed explanation wonderfully explained in console-application-with-java-and-gradle

How to create a Kotlin console application with Gradle in Intellij IDEA

The wizard you have seems to be obsolete now. There was a brand-new one, released as a part of Kotlin 1.4 recently(see here).
Most probably, the problem is caused by the Kotlin IDE plugin being outdated or something. Please try to delete in and re-install using the Preferences -> Plugins menu. Comment here with the results, please. I'd like to know if this would help.

Application built with Gradle starts successfully from IDE, but not from console

You should probably use the application plugin of Gradle. It provides a run task that has the classpath set up correctly and also tasks for building distributable packages with Windows and *nix start scripts that set up the classpath as needed.

Besides that, if what you have shown is your full build.gradle, the whole buildscript block is non-sense. You add Jackson to the classpath of the build script but you don't use it anywhere. In the buildscript block you add dependencies you need in the build script, like some Gradle plugins and so on.

how to produce a 'fatjar' for a simple console application with gradle kotlin dsl

As @hotkey pointed out you can use the https://github.com/johnrengelman/shadow plugin like so:

In your depedencies and the following:

classpath 'com.github.jengelman.gradle.plugins:shadow:<version>'

Replace <version> with the current version.

And apply the plugin:

apply plugin: 'com.github.johnrengelman.shadow'

Then you are able to use the shadowJar task.



Related Topics



Leave a reply



Submit