Gradle System.in无法读取Windows EOL

时间:2015-11-08 16:59:08

标签: java gradle build.gradle

我已经准备了一个显示一些问题的简单示例。以下代码应重复用户输入(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!!!");    
  }
}

从Windows命令行运行它,通过java工作正常。

gradlew.bat -q myrun运行它会阻止在Windows EOF中读取。引用Enter会导致光标转到新行,但应用程序不会读取它。

D:\application>gradlew.bat -q myrun
prompt> sometext
again
nothing

gradlew.bat基于以下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'
}

0 个答案:

没有答案