-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbuild.gradle.kts
More file actions
190 lines (154 loc) · 5.44 KB
/
build.gradle.kts
File metadata and controls
190 lines (154 loc) · 5.44 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
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
187
188
189
190
import de.undercouch.gradle.tasks.download.Download
import org.glavo.hmcl.update.CheckExisting
import org.glavo.hmcl.update.CheckUpdate
import org.glavo.hmcl.update.UpdateChannel
import java.nio.file.Files
import java.security.MessageDigest
plugins {
signing
`maven-publish`
id("io.github.gradle-nexus.publish-plugin") version "2.0.0"
id("de.undercouch.download") version "5.6.0"
}
group = "org.glavo.hmcl"
val hmclChannel = project.findProperty("hmcl.channel")?.let { name ->
UpdateChannel.entries.find { channel ->
channel.name.contentEquals(name.toString(), true)
} ?: throw GradleException("channel '$name' is not defined")
} ?: throw GradleException("hmcl.channel is not defined")
CheckUpdate.apply(project, hmclChannel)
val hmclVersion: String = ext.get(CheckUpdate.HMCL_VERSION).toString()
val hmclDownloadBaseUri: String = ext.get(CheckUpdate.HMCL_DOWNLOAD_BASE_URI).toString()
version = hmclVersion
val existing = CheckExisting.checkExisting(hmclChannel, hmclVersion)
val downloadDir = layout.buildDirectory.dir("downloads")
val upload by tasks.registering {
if (!existing) {
dependsOn("publishToSonatype", "closeAndReleaseSonatypeStagingRepository")
}
}
val downloadArtifacts by tasks.registering(Download::class) {
src("$hmclDownloadBaseUri/HMCL-$hmclVersion.jar")
src("$hmclDownloadBaseUri/HMCL-$hmclVersion.jar.sha256")
overwrite(false)
quiet(false)
dest(downloadDir)
retries(5)
}
val verifyArtifacts by tasks.registering {
dependsOn(downloadArtifacts)
doLast {
val dir = downloadDir.get().asFile.toPath()
val expected = Files.readString(dir.resolve("HMCL-$hmclVersion.jar.sha256")).trim()
val digest = MessageDigest.getInstance("SHA-256")
digest.update(Files.readAllBytes(dir.resolve("HMCL-$hmclVersion.jar")))
val actual = digest.digest().toHexString()
if (!expected.contentEquals(actual, true)) {
throw GradleException("Checksum not matching: expected $expected, actual $actual")
}
}
}
val javadocJar by tasks.registering(Jar::class) {
archiveBaseName.set("HMCL")
archiveClassifier.set("javadoc")
archiveVersion.set(hmclVersion)
}
val sourcesJar by tasks.registering(Jar::class) {
archiveBaseName.set("HMCL")
archiveClassifier.set("sources")
archiveVersion.set(hmclVersion)
}
tasks.withType<GenerateModuleMetadata> {
enabled = false
}
tasks.withType<Sign> {
dependsOn(verifyArtifacts, javadocJar, sourcesJar)
}
tasks.withType<GenerateMavenPom> {
dependsOn(verifyArtifacts, javadocJar, sourcesJar)
}
val hmclPublication = publishing.publications.create<MavenPublication>("hmcl") {
groupId = project.group.toString()
artifactId = hmclChannel.mavenArtifactId
version = hmclVersion
artifact(downloadDir.map { it.file("HMCL-$hmclVersion.jar") }) {
builtBy(verifyArtifacts)
this.extension = "jar"
this.classifier = ""
}
artifact(sourcesJar)
artifact(javadocJar)
pom {
name.set("Hello Minecraft! Launcher ")
description.set("A Minecraft Launcher which is multi-functional, cross-platform and popular")
url.set("https://github.com/HMCL-dev/HMCL")
licenses {
license {
name.set("GPL 3.0")
url.set("https://www.gnu.org/licenses/gpl-3.0.html")
}
}
developers {
developer {
id.set("huanghongxun")
name.set("Yuhui Huang")
email.set("jackhuang1998@gmail.com")
}
developer {
id.set("Glavo")
name.set("Glavo")
email.set("zjx001202@gmail.com")
}
}
scm {
url.set("https://github.com/HMCL-dev/HMCL")
}
}
}
// Maven Central
var secretPropsFile = project.rootProject.file("gradle/maven-central-publish.properties")
if (!secretPropsFile.exists()) {
secretPropsFile =
file(System.getProperty("user.home")).resolve(".gradle").resolve("maven-central-publish.properties")
}
if (secretPropsFile.exists()) {
// Read local.properties file first if it exists
val p = java.util.Properties()
secretPropsFile.reader().use {
p.load(it)
}
p.forEach { (name, value) ->
rootProject.ext[name.toString()] = value
}
}
listOf(
"sonatypeUsername" to "SONATYPE_USERNAME",
"sonatypePassword" to "SONATYPE_PASSWORD",
// "sonatypeStagingProfileId" to "SONATYPE_STAGING_PROFILE_ID",
"signing.keyId" to "SIGNING_KEY_ID",
"signing.password" to "SIGNING_PASSWORD",
"signing.key" to "SIGNING_KEY"
).forEach { (p, e) ->
if (!rootProject.ext.has(p)) {
rootProject.ext[p] = System.getenv(e)
}
}
signing {
useInMemoryPgpKeys(
rootProject.ext["signing.keyId"].toString(),
rootProject.ext["signing.key"].toString(),
rootProject.ext["signing.password"].toString(),
)
sign(publishing.publications["hmcl"])
}
nexusPublishing {
repositories {
sonatype {
nexusUrl.set(uri("https://ossrh-staging-api.central.sonatype.com/service/local/"))
snapshotRepositoryUrl.set(uri("https://central.sonatype.com/repository/maven-snapshots/"))
// stagingProfileId.set(rootProject.ext["sonatypeStagingProfileId"].toString())
username.set(rootProject.ext["sonatypeUsername"].toString())
password.set(rootProject.ext["sonatypePassword"].toString())
}
}
}