@@ -14,53 +14,32 @@ plugins {
1414
1515group = " org.glavo.hmcl"
1616
17- val buildDir = layout.buildDirectory
18- val downloadDir = buildDir.dir(" downloads" )
19-
20- val channel = project.findProperty(" hmcl.channel" )?.let { name ->
17+ val hmclChannel = project.findProperty(" hmcl.channel" )?.let { name ->
2118 UpdateChannel .entries.find { channel ->
2219 channel.name.contentEquals(name.toString(), true )
2320 } ? : throw GradleException (" channel '$name ' is not defined" )
2421} ? : throw GradleException (" hmcl.channel is not defined" )
2522
26- val checkUpdate by tasks.registering(CheckUpdate ::class ) {
27- channel.set(channel)
2823
29- }
24+ CheckUpdate . apply (project, hmclChannel)
3025
31- val hmclVersion by lazy {
32- project.ext[CheckUpdate .HMCL_VERSION ]?.toString()
33- ? : throw GradleException (" ${CheckUpdate .HMCL_VERSION } is not defined" )
34- }
26+ val hmclVersion: String = ext.get(CheckUpdate .HMCL_VERSION ).toString()
27+ val hmclDownloadBaseUri: String = ext.get(CheckUpdate .HMCL_DOWNLOAD_BASE_URI ).toString()
3528
36- val checkExisting by tasks.registering(CheckExisting ::class ) {
37- dependsOn(checkUpdate)
29+ version = hmclVersion
3830
39- onlyIf {
40- ext.has(CheckUpdate .HMCL_VERSION ) && ext.has(CheckUpdate .HMCL_DOWNLOAD_BASE_URI )
41- }
42-
43- checkUpdate.get().doLast {
44- hmclVersion.set(hmclVersion)
45- }
31+ val downloadDir = layout.buildDirectory.dir(" downloads" )
4632
47- channel.set(channel)
33+ val checkExisting by tasks.registering(CheckExisting ::class ) {
34+ version.set(hmclVersion)
35+ channel.set(hmclChannel)
4836}
4937
50- val needUpdate by lazy { ext.has(CheckExisting .NEED_UPDATE ) }
51-
5238val downloadArtifacts by tasks.registering(Download ::class ) {
5339 dependsOn(checkExisting)
5440
55- onlyIf { needUpdate }
56-
57- checkUpdate.get().doLast {
58- val hmclDownloadUrlBase = project.ext[CheckUpdate .HMCL_DOWNLOAD_BASE_URI ]?.toString()
59- ? : throw GradleException (" ${CheckUpdate .HMCL_DOWNLOAD_BASE_URI } is not defined" )
60-
61- src(" $hmclDownloadUrlBase /HMCL-$hmclVersion .jar" )
62- src(" $hmclDownloadUrlBase /HMCL-$hmclVersion .jar.sha256" )
63- }
41+ src(" $hmclDownloadBaseUri /HMCL-$hmclVersion .jar" )
42+ src(" $hmclDownloadBaseUri /HMCL-$hmclVersion .jar.sha256" )
6443
6544 overwrite(false )
6645 quiet(false )
@@ -71,8 +50,6 @@ val downloadArtifacts by tasks.registering(Download::class) {
7150val verifyArtifacts by tasks.registering {
7251 dependsOn(downloadArtifacts)
7352
74- onlyIf { needUpdate }
75-
7653 doLast {
7754 val dir = downloadDir.get().asFile.toPath()
7855 val expected = Files .readString(dir.resolve(" HMCL-$hmclVersion .jar.sha256" )).trim()
@@ -88,52 +65,45 @@ val verifyArtifacts by tasks.registering {
8865}
8966
9067val javadocJar by tasks.registering(Jar ::class ) {
91- dependsOn(checkExisting)
92-
93- onlyIf { needUpdate }
94-
9568 archiveBaseName.set(" HMCL" )
9669 archiveClassifier.set(" javadoc" )
9770
98- checkUpdate.get().doLast {
99- archiveVersion.set(hmclVersion)
100- }
71+ archiveVersion.set(hmclVersion)
10172}
10273
10374val sourcesJar by tasks.registering(Jar ::class ) {
104- dependsOn(checkExisting)
105-
106- onlyIf { needUpdate }
107-
10875 archiveBaseName.set(" HMCL" )
10976 archiveClassifier.set(" sources" )
11077
111- checkUpdate.get().doLast {
112- archiveVersion.set(hmclVersion)
113- }
78+ archiveVersion.set(hmclVersion)
11479}
11580
11681tasks.withType<GenerateModuleMetadata > {
11782 enabled = false
11883}
11984
85+ tasks.withType<Sign > {
86+ dependsOn(verifyArtifacts, javadocJar, sourcesJar)
87+ }
88+
89+ tasks.withType<GenerateMavenPom > {
90+ dependsOn(verifyArtifacts, javadocJar, sourcesJar)
91+ }
92+
12093val hmclPublication = publishing.publications.create<MavenPublication >(" hmcl" ) {
12194 groupId = project.group.toString()
122- artifactId = channel.mavenArtifactId
123-
124- checkUpdate.get().doLast {
125- if (ext.has(CheckUpdate .HMCL_VERSION )) {
126- version = hmclVersion
127- artifact(downloadDir.map { " HMCL-$hmclVersion .$ext " }) {
128- this .extension = " jar"
129- this .classifier = " "
130- }
95+ artifactId = hmclChannel.mavenArtifactId
13196
132- artifact(sourcesJar)
133- artifact(javadocJar)
134- }
97+ version = hmclVersion
98+ artifact(downloadDir.map { it.file(" HMCL-$hmclVersion .jar" ) }) {
99+ builtBy(verifyArtifacts)
100+ this .extension = " jar"
101+ this .classifier = " "
135102 }
136103
104+ artifact(sourcesJar)
105+ artifact(javadocJar)
106+
137107 pom {
138108 name.set(" Hello Minecraft! Launcher " )
139109 description.set(" A Minecraft Launcher which is multi-functional, cross-platform and popular" )
0 commit comments