在build.gradle
添加一下代码,编程完成后会输出耗时>100ms的任务
public class BuildTimeListener implements TaskExecutionListener, BuildListener {
private Clock clock
private times = []
@Override
void buildStarted(Gradle gradle) {
}
@Override
void settingsEvaluated(Settings settings) {
}
@Override
void projectsLoaded(Gradle gradle) {
}
@Override
void projectsEvaluated(Gradle gradle) {
}
@Override
void buildFinished(BuildResult result) {
println "Task spend time:"
for (time in times) {
if (time[0] >= 100) {
printf "%7sms %s\n", time
}
}
}
@Override
void beforeExecute(Task task) {
clock = new org.gradle.util.Clock()
}
@Override
void afterExecute(Task task, TaskState state) {
def ms = clock.timeInMs
times.add([ms, task.path])
}
}
project.gradle.addListener(new BuildTimeListener())