Gradle 명령어 모음

작성일: 2024-03-05 18:32

# Dependency Tree 출력

./gradlew dependencies >> ~/temp.txt
1

# 태스크 실행 전후 로그 추가하기

gradle.taskGraph.beforeTask { Task task ->
    println "### beforeTask $task"
}

gradle.taskGraph.afterTask { Task task, TaskState state ->
    println "### afterTask $task $state.failure"
}
1
2
3
4
5
6
7

# 태스크 실행 전후 로그 추가 및 시간 측정

class TimingsListener implements TaskExecutionListener, BuildListener {

    private long startTime
    private timings = []

    @Override
    void settingsEvaluated(Settings settings) {

    }

    @Override
    void projectsLoaded(Gradle gradle) {

    }

    @Override
    void projectsEvaluated(Gradle gradle) {

    }

    @Override
    void beforeExecute(Task task) {
        println "### beforeExecute $task"
        startTime = System.currentTimeMillis()
    }

    @Override
    void afterExecute(Task task, TaskState state) {
        long ms = System.currentTimeMillis() - startTime
        timings.add([ms, task.path])
        println "### afterExecute $task $state.failure took ${ms}ms"
    }

    @Override
    void buildFinished(BuildResult buildResult) {
        println "Task timings:"
        long total = 0
        timings.sort { a, b -> b[0] - a[0] }
        for (timing in timings) {
            total += timing[0]
            if (timing[0] > 0) {
                printf "%7sms %s\n", timing
            }
        }
        println "Total: ${total}ms"
    }
}

gradle.addListener new TimingsListener()
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49

# 참고 자료