Gradle print与println

时间:2017-01-25 14:18:29

标签: gradle groovy stdout stderr println

我理解printprintln方法之间的区别。 但是,为什么具有默认日志记录级别的Gradle打印输出println但不与printprintf打印?

TaskProgress.groovy

public class TaskProgress {

    private static final String PROGRESS_SYMBOLS = '_/\\_';
    private static final int MAX_POINTS = PROGRESS_SYMBOLS.length() - 2

    AtomicBoolean inProgress = new AtomicBoolean(true)
    int currentChar = 0
    int delta = 1

    private TaskProgress() {}

    static TaskProgress doProgress() {
        Log.error("START PROGRESS")
        def taskProgress = new TaskProgress();
        taskProgress.startProgress()
        return taskProgress
    }

    private void startProgress() {
        Thread.start {
            Log.error('STARTING:')
            while (inProgress.get()) {
                if (currentChar > MAX_POINTS) {
                    delta = -1
                } else if (currentChar == 0) {
                    delta = 1
                }
                println PROGRESS_SYMBOLS[currentChar] // it works
                print PROGRESS_SYMBOLS[currentChar] // it doesn't work
                currentChar += delta
                if (!inProgress.get()) break;
            }
            Log.error('STOPPING:')
        }
    }

    public void stopProgress() {
        Log.error("STOP PROGRESS")
        inProgress.set(false)
    }

}

buid.gradle

task progress {
    doLast {
        def progress = TaskProgress.doProgress()
        Thread.sleep(1000)
        progress.stopProgress()
    }
}

当我在主线程中使用print时,它可以正常工作。这是一个缺陷吗? 我在官方gradle论坛上提出了一个主题:Gradle print vs println

0 个答案:

没有答案