我理解print
和println
方法之间的区别。
但是,为什么具有默认日志记录级别的Gradle打印输出println
但不与print
或printf
打印?
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