I have prepaired a simple example which shows some issue. The below code, should repeat an user input (echo).
package org.gradle.sample;
import java.io.IOException;
import jline.TerminalFactory;
import jline.console.ConsoleReader;
public class Main {
public static void main(String[] args) {
try {
ConsoleReader console = new ConsoleReader();
console.setPrompt("prompt> ");
String line = null;
while ((line = console.readLine()) != null) {
console.println(line);
}
} catch(IOException e) {
e.printStackTrace();
} finally {
try {
TerminalFactory.get().restore();
} catch(Exception e) {
e.printStackTrace();
}
}
System.out.println("Finish!!!");
}
}
Running it from Windows’ command line, by java works fine.
Running it by gradlew.bat -q myrun
prevents to read in Windows EOF. Hiting Enter
causes that a cursor goes to a new line, but it is not read by application.
D:\application>gradlew.bat -q myrun
prompt> sometext
again
nothing
gradlew.bat is generated based on the following build.gradle
apply plugin: 'java'
apply plugin: 'application'
version = '1.0.2'
applicationDefaultJvmArgs = ["-Dgreeting.language=en"]
task wrapper(type: Wrapper) {
gradleVersion = '2.8'
}
repositories {
mavenCentral()
}
dependencies {
compile 'commons-collections:commons-collections:3.2.1'
compile 'jline:jline:+'
}
task myrun(type:org.gradle.api.tasks.Exec, dependsOn: classes) {
def classpath = sourceSets.main.runtimeClasspath + configurations.runtime
standardInput = System.in
commandLine 'java',
'-version:1.8+',
'-cp', classpath.collect().join(System.getProperty('path.separator')),
'org.gradle.sample.Main'
}