This repository has been archived by the owner on Mar 6, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.gradle.kts
186 lines (158 loc) · 5.05 KB
/
build.gradle.kts
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
import org.jetbrains.kotlin.konan.file.bufferedReader
plugins {
java
`maven-publish`
id("org.jetbrains.kotlin.jvm") version "1.6.0-RC"
}
repositories {
mavenLocal()
maven {
url = uri("https://repo.maven.apache.org/maven2/")
}
mavenCentral()
}
val jcommanderVersion = "1.81"
val hutoolVersion = "5.7.16"
val oshiVersion = "5.8.5"
val emojiVersion = "5.1.1"
val zxingVersion = "3.4.1"
val pinyinVersion = "2.5.1"
val fastjsonVersion = "1.2.78"
val javassistVersion = "3.28.0-GA"
val junitVersion = "4.13.2"
val chalkVersion = "1.0.2"
val qlExpressVersion = "3.2.6"
dependencies {
implementation("com.beust:jcommander:$jcommanderVersion")
implementation("cn.hutool:hutool-core:$hutoolVersion")
implementation("cn.hutool:hutool-system:$hutoolVersion")
implementation("com.github.oshi:oshi-core:$oshiVersion")
implementation("cn.hutool:hutool-crypto:$hutoolVersion")
implementation("cn.hutool:hutool-http:$hutoolVersion")
implementation("cn.hutool:hutool-script:$hutoolVersion")
implementation("cn.hutool:hutool-extra:$hutoolVersion")
implementation("com.vdurmont:emoji-java:$emojiVersion")
implementation("com.google.zxing:core:$zxingVersion")
implementation("com.belerweb:pinyin4j:$pinyinVersion")
implementation("com.alibaba:fastjson:$fastjsonVersion")
implementation("org.javassist:javassist:$javassistVersion")
implementation("com.github.tomas-langer:chalk:$chalkVersion")
implementation("com.alibaba:QLExpress:$qlExpressVersion")
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
implementation("org.bouncycastle:bcprov-jdk15on:1.69")
testImplementation("junit:junit:$junitVersion")
}
val group = "org.code4everything"
val version = "1.5"
val hutoolCliVersion = version
val description = "hutool-cli"
java.sourceCompatibility = JavaVersion.VERSION_1_8
publishing {
publications {
create<MavenPublication>("maven") {
from(components["java"])
}
}
}
tasks.withType<JavaCompile> {
options.encoding = "UTF-8"
}
tasks.jar {
archiveFileName.set("hutool.jar")
manifest {
attributes(mapOf("Manifest-Version" to "1.0", "Main-Class" to "org.code4everything.hutool.Hutool"))
}
from(configurations.runtimeClasspath.get().files.map { if (it.isDirectory) it else zipTree(it) })
exclude("META-INF/*.RSA")
exclude("META-INF/*.SF")
exclude("META-INF/*.DSA")
exclude("META-INF/AL2.0")
exclude("META-INF/LGPL2.1")
exclude("META-INF/LICENSE")
exclude("META-INF/LICENSE.txt")
exclude("META-INF/NOTICE.txt")
exclude("META-INF/versions/9/module-info.class")
}
val isWin = System.getProperty("os.name").toLowerCase().contains("windows")
tasks.build {
doFirst {
val stream = Runtime.getRuntime().exec("git pull").inputStream
val reader = bufferedReader(stream)
while (true) {
val line: String? = reader.readLine()
if (line == null) break else println(line)
}
}
doLast {
copy {
from("./build/libs/hutool.jar")
into("./hutool")
}
}
}
tasks.register("pack") {
group = "build"
description = "Clean and build a executable jar, then move to './hutool' folder."
dependsOn("clean", "build")
}
tasks.register("install") {
group = "build"
description = "Execute pack task, then build './src/main/go/hutool.go'."
dependsOn("pack")
exec {
workingDir("./src/main/go")
if (isWin) {
commandLine("cmd", "/c", "go build hutool.go")
} else {
commandLine("bash", "-c", "go build hutool.go")
}
}
copy {
from("./src/main/go")
into("./hutool/bin")
exclude("hutool.go")
rename("hutool", "hu")
}
delete("./src/main/go/hutool.exe")
delete("./src/main/go/hutool")
}
val platforms = listOf("windows", "linux", "darwin")
for (i in platforms.indices) {
tasks.register("release$i") {
val osName = platforms[i]
group = "build"
description = "Only build go for $osName platform."
if (isWin) {
return@register
}
exec {
workingDir("./src/main/go")
commandLine("bash", "-c", "CGO_ENABLED=0 GOOS=${osName} GOARCH=amd64 go build hutool.go")
}
copy {
from("./src/main/go")
into("./hutool/bin/")
exclude("hutool.go")
val newName = if (osName == "darwin") "hu-mac" else "hu"
rename("hutool", newName)
}
delete("./src/main/go/hutool.exe")
delete("./src/main/go/hutool")
}
}
tasks.register("release", type = Zip::class) {
group = "build"
description = "Build jar and go, and zip it to a publishable zip."
dependsOn("pack", "release0", "release1", "release2")
archiveFileName.set("hu-${hutoolCliVersion}.zip")
destinationDirectory.set(File("."))
from("./hutool")
exclude("method")
exclude("*.json")
}
tasks.compileKotlin {
kotlinOptions.jvmTarget = "1.8"
}
tasks.compileTestKotlin {
kotlinOptions.jvmTarget = "1.8"
}