-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.gradle.kts
More file actions
103 lines (87 loc) · 3.3 KB
/
Copy pathbuild.gradle.kts
File metadata and controls
103 lines (87 loc) · 3.3 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
group = "com.acebear.sample"
version = "1.0.0"
plugins {
java
id("org.springframework.boot") version "2.2.1.RELEASE"
}
repositories {
val maven = "maven"
val aliyun = "maven.aliyun.com"
if(project.properties[maven]?.equals(aliyun) == true)
maven("https://maven.aliyun.com/repository/public")
else
mavenCentral()
}
dependencies {
implementation("org.springframework.boot:spring-boot-starter:2.2.+"){
exclude("org.springframework.boot", "spring-boot-starter-logging")
}
implementation("org.slf4j:slf4j-api:1.7.+")
implementation("org.apache.logging.log4j:log4j-core:2.12.+")
runtimeOnly("org.apache.logging.log4j:log4j-slf4j-impl:2.12.+")
// Use JUnit test framework
testImplementation("junit:junit:4.12")
}
tasks.create("markGitVersion"){
fun String.execute(): String {
try {
val parts = this.split("\\s".toRegex())
val proc = ProcessBuilder(*parts.toTypedArray())
.directory(projectDir)
.redirectOutput(ProcessBuilder.Redirect.PIPE)
.redirectError(ProcessBuilder.Redirect.PIPE)
.start()
proc.waitFor(8, TimeUnit.SECONDS)
return proc.inputStream.bufferedReader().readText().trim()
} catch(ex: java.io.IOException) {
ex.printStackTrace()
return ex.message?:"IOException"
}
}
doFirst {
val git = "git -C $projectDir "
val branch = (git + "symbolic-ref --short HEAD").execute()
val rev = (git + "rev-list --count HEAD").execute()
val hash = (git + "rev-parse --short HEAD").execute()
val hash160 = (git + "rev-parse HEAD").execute()
val remote = (git + "remote").execute().split("\n").get(0)
val url = (git + "remote get-url $remote").execute()
val status = if((git + "status -s").execute().isBlank()) "@" else "+"
println("\tMark Git Version: $branch.$rev$status$hash\n\t$remote : $url")
val pkg = project.group.toString()
val pkgSlash = pkg.replace(".", "/")
var javaFileContent = File(projectDir, "src/main/java/$pkgSlash/GitVer.jav_").readText()
javaFileContent = javaFileContent
.replace("\$package\$", pkg)
.replace("\$branch\$", branch)
.replace("\$rev\$", rev)
.replace("\$hash\$", hash)
.replace("\$hash160\$", hash160)
.replace("\$sourceLink\$", url)
val file = File(projectDir, "src/main/java/$pkgSlash/GitVer.java")
file.writeText(javaFileContent)
}
}
tasks.withType<JavaCompile>(){
options.encoding = "utf-8"
options.compilerArgs.add("-Xlint:unchecked")
options.compilerArgs.add("-Xdiags:verbose")
dependsOn("markGitVersion")
}
tasks.named<JavaExec>("bootRun"){
systemProperties(System.getProperties().mapKeys { it.key as String })
}
tasks.withType<Test>(){
systemProperties(System.getProperties().mapKeys { it.key as String })
testLogging{
events("passed", "skipped", "failed")
showStandardStreams = true
}
val testCaseOnly = "testCaseOnly"
if(project.hasProperty(testCaseOnly)){
filter{
includeTestsMatching(project.properties[testCaseOnly]?.toString())
}
}
}
defaultTasks("assemble")