forked from constanline/XQuickEnergy
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.gradle
67 lines (62 loc) · 1.86 KB
/
build.gradle
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
buildscript {
repositories {
maven { url 'https://maven.aliyun.com/repository/public/' }
maven { url 'https://maven.aliyun.com/repository/google/'}
maven { url 'https://maven.aliyun.com/repository/jcenter/'}
google()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:8.5.2'
}
}
allprojects {
repositories {
maven { url 'https://maven.aliyun.com/repository/public/' }
maven { url 'https://maven.aliyun.com/repository/google/'}
maven { url 'https://maven.aliyun.com/repository/jcenter/'}
google()
mavenCentral()
}
}
tasks.register('clean', Delete) {
delete rootProject.buildDir
}
//监听任务
gradle.taskGraph.whenReady { graph ->
def allTask = graph.getAllTasks()
allTask.each { task ->
def name = task.name.toLowerCase()
if (name.contains("debugandroidtest")) {
task.enabled = false
}
}
List<String> names = new ArrayList<>()
def addTasks = allTask.findAll { task ->
def name = task.name.toLowerCase()
boolean add = name.startsWith("assemble") && !name.endsWith("test")
if (add) System.err.println("开始Gradle任务:${task.name}")
if (add && !names.contains(task.name)) names.add(task.name)
add
}
addTasks.each { task ->
task.doLast {
System.err.println("已完成Gradle任务:${task.name}")
names.remove(task.name)
if (names.isEmpty()) killJavaAfterFinish()
}
}
}
//释放内存
static void killJavaAfterFinish() {
System.err.println("Gradle任务已全部完成,5秒后释放java进程,${new Date().format("yyyy-MM-dd HH:mm:ss")}")
new Thread() {
@Override
void run() {
sleep(5_000)
System.err.println("开始执行释放java占用任务")
String cmd = "taskkill /f /t /im java.exe"
cmd.execute().text.trim()
}
}.start()
}