我正在尝试使用this代码摘录来拦截gradle日志到文件中。我不想对我的build.gradle
进行审核,因此,我创建了一个interceptor.gradle
来封装这个逻辑。它看起来像是:
interceptor.gradle
import org.gradle.logging.internal.*
task intercept {
def outputStream = new File("gradle.log")
gradle.services.get(LoggingOutputInternal).addStandardOutputListener (new StandardOutputListener () {
void onOutput(CharSequence output) {
outputStream << output
}
}
)
}
在我的build.gradle
中,我添加了:
apply from: project.file('tooling/gradle/interceptor.gradle')
问题是:当我尝试./gradlew build
时,我得到了:
* What went wrong:
A problem occurred evaluating script.
> Could not get unknown property 'LoggingOutputInternal' for task ':intercept' of type org.gradle.api.DefaultTask.
如何隔离拦截gradle日志的代码并将其保存到单独的gradle脚本中的文件中并使其从主build.gradle
执行?
答案 0 :(得分:1)
尝试使用此导入import org.gradle.internal.logging.*
import org.gradle.internal.logging.*
task intercept {
def outputStream = new File("gradle.log")
gradle.services.get(LoggingOutputInternal).addStandardOutputListener (new StandardOutputListener () {
void onOutput(CharSequence output) {
outputStream << output
}
}
)
}