我的目标是在任务运行时将消息打印到控制台idea
,但不幸的是,无论何时运行任何内容都会打印该消息。为什么在idea
任务未运行时执行打印行?如何仅在idea
执行任务时显示消息?
构建.gradle
apply plugin: 'idea'
task hello << {
println 'Hello world!'
}
tasks.idea() {
println '*********************************************************'
println '* You should open build.gradle as a native project from *'
println '* within IntelliJ. *'
println '*********************************************************'
}
命令的输出gradle hello
*********************************************************
* You should open build.gradle as a native project from *
* within IntelliJ. *
*********************************************************
:hello
Hello world!
BUILD SUCCESSFUL
Total time: 2.846 secs
工作解决方案
tasks.getByPath('idea') << {
println '*********************************************************'
println '* You should open build.gradle as a native project from *'
println '* within IntelliJ. *'
println '*********************************************************'
}