0
我已經編寫了一個任務,使用通過用戶輸入選擇的主類來運行我的項目,但是當我運行gradle tasks
時,它提示我選擇主類。爲什麼是這樣的,我如何防止它?不必要地運行任務
task run(dependsOn: "classes", type: JavaExec) {
description "Executes the project using the selected main class"
def selection = null
def mainClasses = []
// Select the java files with main classes in
sourceSets.main.allJava.each {
if(it.text.contains("public static void main")) {
def pkg = relativePath(it) - 'src/main/java/' - '.java'
pkg = pkg.tr "/", "."
println "${mainClasses.size()}. $pkg"
mainClasses << pkg
}
}
// Now prompt the user to choose a main class to use
while(selection == null) {
def input = System.console().readLine "#? "
if(input?.isInteger()) {
selection = input as int
if(selection >= 0 && selection < mainClasses.size()) {
break
} else {
selection = null
}
} else if(input?.toLowerCase() == "quit") {
return
}
if(selection == null) {
println "Unknown option."
}
}
main = mainClasses[selection]
classpath = sourceSets.main.runtimeClasspath
}
當我添加一個'doLast'關閉用戶系統不會提示用戶,奇怪當我使用'doFirst'時足以提示用戶。 – Lerp