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;
- Add below task in your
build.gradle
.
run{
standardInput = System.in
}
- 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
Java Static Initialization Order
How to Set Jvm Parameters for Junit Unit Tests
Comparing Boxed Long Values 127 and 128
Java 8 Stream with Batch Processing
JPA - Returning an Auto Generated Id After Persist()
How to Autowire Bean of Generic Type <T> in Spring
In Java 8, Why Is the Default Capacity of Arraylist Now Zero
Java Code for Getting Current Time
How to Copy the Contents of One Arraylist into Another
Parsing a Fixed-Width Formatted File in Java
Eclipse Error: Could Not Find or Load Main Class
How to Implement a Fsm - Finite State MAChine in Java
How to Get Java Logging Output to Appear on a Single Line
Java:Does Wait() Release Lock from Synchronized Block
Maven "Build Path Specifies Execution Environment J2Se-1.5", Even Though I Changed It to 1.7
Accessing Java Static Final Variable Value Through Reflection