1+ /*
2+ * Hello Minecraft! Launcher
3+ * Copyright (C) 2025 huangyuhui <[email protected] > and contributors 4+ *
5+ * This program is free software: you can redistribute it and/or modify
6+ * it under the terms of the GNU General Public License as published by
7+ * the Free Software Foundation, either version 3 of the License, or
8+ * (at your option) any later version.
9+ *
10+ * This program is distributed in the hope that it will be useful,
11+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
12+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+ * GNU General Public License for more details.
14+ *
15+ * You should have received a copy of the GNU General Public License
16+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
17+ */
18+
19+ import java.security.MessageDigest
20+
21+ plugins {
22+ id(" java-library" )
23+ id(" signing" )
24+ id(" maven-publish" )
25+ id(" io.github.gradle-nexus.publish-plugin" ) version " 2.0.0"
26+ id(" de.undercouch.download" ) version " 5.6.0"
27+ id(" org.glavo.load-maven-publish-properties" ) version " 0.1.0"
28+ }
29+
30+ group = " org.glavo.hmcl"
31+ version = project.findProperty(" version" ) ? : throw GradleException (" Version not specified" )
32+ description = " HMCLauncher for Windows"
33+
34+ val downloadDir = layout.buildDirectory.dir(" downloads" )
35+
36+ val downloadVerifyFile by tasks.registering(de.undercouch.gradle.tasks.download.Download ::class ) {
37+ src(" https://github.com/HMCL-dev/HMCLauncher/releases/download/$version /HMCLauncher.exe.sha256" )
38+ dest(downloadDir.map { it.file(" HMCLauncher-$version .exe.sha256" ) })
39+ overwrite(false )
40+ }
41+
42+ val downloadLauncher by tasks.registering(de.undercouch.gradle.tasks.download.Download ::class ) {
43+ src(" https://github.com/HMCL-dev/HMCLauncher/releases/download/$version /HMCLauncher.exe" )
44+ dest(downloadDir.map { it.file(" HMCLauncher-$version .exe" ) })
45+ overwrite(false )
46+ }
47+
48+ val verifyLauncher by tasks.registering {
49+ dependsOn(downloadLauncher, downloadVerifyFile)
50+
51+ doLast {
52+ val expectedChecksum = downloadVerifyFile.get().outputFiles.single().readText().trim()
53+ val actualChecksum = downloadLauncher.get().outputFiles.single().readBytes().let { bytes ->
54+ MessageDigest .getInstance(" SHA-256" ).digest(bytes).joinToString(" " ) { " %02x" .format(it) }
55+ }
56+
57+ if (! expectedChecksum.equals(actualChecksum, true )) {
58+ throw GradleException (" Checksum verification failed: expected $expectedChecksum , got $actualChecksum " )
59+ }
60+ }
61+ }
62+
63+ tasks.processResources {
64+ dependsOn(downloadLauncher, verifyLauncher)
65+
66+ into(" assets" ) {
67+ from(downloadLauncher.map { it.outputFiles.single() }) {
68+ rename { " HMCLauncher.exe" }
69+ }
70+ }
71+ }
72+
73+ java {
74+ withJavadocJar()
75+ withSourcesJar()
76+ }
77+
78+ publishing {
79+ publications {
80+ create<MavenPublication >(" hmclauncher" ) {
81+ from(components[" java" ])
82+
83+ pom {
84+ name.set(project.name)
85+ description.set(project.description)
86+ url.set(" https://github.com/HMCL-dev/HMCLauncher" )
87+ licenses {
88+ license {
89+ name.set(" GPL 3.0" )
90+ url.set(" https://www.gnu.org/licenses/gpl-3.0.html" )
91+ }
92+ }
93+ developers {
94+ developer {
95+ id.set(" huanghongxun" )
96+ name.set(" Yuhui Huang" )
97+ 98+ }
99+
100+ developer {
101+ id.set(" Glavo" )
102+ name.set(" Glavo" )
103+ 104+ }
105+ }
106+ scm {
107+ url.set(" https://github.com/HMCL-dev/HMCLauncher" )
108+ }
109+ }
110+ }
111+ }
112+ }
113+
114+ signing {
115+ useInMemoryPgpKeys(
116+ rootProject.ext[" signing.keyId" ].toString(),
117+ rootProject.ext[" signing.key" ].toString(),
118+ rootProject.ext[" signing.password" ].toString(),
119+ )
120+ sign(publishing.publications[" hmclauncher" ])
121+ }
122+
123+ // ./gradlew publishToSonatype closeAndReleaseSonatypeStagingRepository
124+ nexusPublishing {
125+ repositories {
126+ sonatype {
127+ nexusUrl.set(uri(" https://ossrh-staging-api.central.sonatype.com/service/local/" ))
128+ snapshotRepositoryUrl.set(uri(" https://central.sonatype.com/repository/maven-snapshots/" ))
129+
130+ username.set(rootProject.ext[" sonatypeUsername" ].toString())
131+ password.set(rootProject.ext[" sonatypePassword" ].toString())
132+ }
133+ }
134+ }
0 commit comments