我正在尝试使用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
主代码执行?
最佳答案
尝试使用此导入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
}
}
)
}
关于gradle - 如何在gradle自定义任务中导入类?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48807514/