-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle
executable file
·71 lines (59 loc) · 1.72 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
68
69
70
71
import org.apache.tools.ant.taskdefs.condition.Os
import java.nio.file.Files
import java.nio.file.Paths
plugins {
id 'java'
id 'com.github.johnrengelman.shadow' version '7.1.0'
}
group 'io.github.zhangt2333'
version '1.0.0-SNAPSHOT'
repositories {
mavenCentral()
}
dependencies {
implementation 'org.javassist:javassist:3.28.0-GA'
testImplementation 'junit:junit:4.13.2'
}
shadowJar {
manifest {
attributes 'Premain-Class': 'io.github.zhangt2333.jmtrace.MemoryTraceAgent'
}
archiveBaseName.set('jmtrace')
archiveClassifier.set('')
archiveVersion.set('')
}
test {
dependsOn shadowJar
jvmArgs([
"-javaagent:" + tasks.shadowJar.archiveFile.get().asFile.path + "=" + "debug=false&test=true"
])
}
task('package', {
doLast {
if (JavaVersion.VERSION_1_8 != JavaVersion.current()) {
System.err.println("Build failed, you should use Java 8, please make sure 'java -version' in your terminal will output 'version 1.8.*'!")
return -1
}
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
System.err.println("Build failed, you should use Ubuntu (18.04 or higher version) but not Windows!")
return -1
}
}
dependsOn shadowJar
doLast {
def binary = """#!/bin/bash
__usage="
Usage: ./jmtrace [-h|--help] class [args...]
(to execute a class)
or ./jmtrace [-h|--help] -jar jarfile [args...]
(to execute a jar file)
"
if [[ \$@ == "" ]] || [[ \$@ == *"-h"* ]] || [[ \$@ == *"--help"* ]]; then
echo "\$__usage"
exit -1
fi
java -javaagent:"${tasks.shadowJar.archiveFile.get().asFile.path}" \$@
"""
Files.write(Paths.get("$projectDir", 'jmtrace'), binary.getBytes());
}
})