-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
build.gradle.kts
200 lines (162 loc) · 5.67 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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import com.matthewprenger.cursegradle.CurseArtifact
import com.matthewprenger.cursegradle.CurseProject
import com.matthewprenger.cursegradle.CurseRelation
import com.matthewprenger.cursegradle.Options
import com.modrinth.minotaur.TaskModrinthUpload
import com.modrinth.minotaur.request.VersionType
import org.ajoberstar.grgit.Grgit
import org.kohsuke.github.GHReleaseBuilder
import org.kohsuke.github.GitHub
buildscript {
dependencies {
classpath("org.kohsuke:github-api:${project.property("github_api_version") as String}")
}
}
plugins {
id("maven-publish")
id("fabric-loom")
id("org.ajoberstar.grgit")
id("org.jetbrains.kotlin.jvm")
id("com.matthewprenger.cursegradle")
id("com.modrinth.minotaur")
}
operator fun Project.get(property: String): String {
return property(property) as String
}
java {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
version = project["mod_version"]
group = project["maven_group"]
val environment: Map<String, String> = System.getenv()
val releaseName = "${name.split("-").joinToString(" ") { it.capitalize() }} ${(version as String).split("+")[0]}"
val releaseType = (version as String).split("+")[0].split("-").let { if(it.size > 1) if(it[1] == "BETA" || it[1] == "ALPHA") it[1] else "ALPHA" else "RELEASE" }
val releaseFile = "${buildDir}/libs/${base.archivesBaseName}-${version}.jar"
val cfGameVersion = (version as String).split("+")[1].let{ if(!project["minecraft_version"].contains("-") && project["minecraft_version"].startsWith(it)) project["minecraft_version"] else "$it-Snapshot"}
fun getChangeLog(): String {
return "A changelog can be found at https://github.com/lucaargolo/$name/commits/"
}
fun getBranch(): String {
environment["GITHUB_REF"]?.let { branch ->
return branch.substring(branch.lastIndexOf("/") + 1)
}
val grgit = try {
extensions.getByName("grgit") as Grgit
}catch (ignored: Exception) {
return "unknown"
}
val branch = grgit.branch.current().name
return branch.substring(branch.lastIndexOf("/") + 1)
}
repositories {
maven {
name = "Fabric"
url = uri("https://maven.fabricmc.net/")
}
maven {
name = "TerraformersMC"
url = uri("https://maven.terraformersmc.com/releases")
}
maven {
name = "Shedaniel"
url = uri("https://maven.shedaniel.me/")
}
mavenLocal()
}
loom {
accessWidenerPath.set(file("src/main/resources/${name.replace("-", "")}.accesswidener"))
}
dependencies {
minecraft("com.mojang:minecraft:${project["minecraft_version"]}")
mappings("net.fabricmc:yarn:${project["yarn_mappings"]}:v2")
modImplementation("net.fabricmc:fabric-loader:${project["loader_version"]}")
modImplementation("net.fabricmc.fabric-api:fabric-api:${project["fabric_version"]}")
modImplementation("net.fabricmc:fabric-language-kotlin:${project["fabric_kotlin_version"]}")
modRuntimeOnly("com.terraformersmc:modmenu:${project["modmenu_version"]}")
modRuntimeOnly("me.shedaniel:RoughlyEnoughItems-fabric:${project["rei_version"]}")
}
tasks.processResources {
duplicatesStrategy = DuplicatesStrategy.INCLUDE
inputs.property("version", project.version)
from(sourceSets["main"].resources.srcDirs) {
include("fabric.mod.json")
expand(mutableMapOf("version" to project.version))
}
from(sourceSets["main"].resources.srcDirs) {
exclude("fabric.mod.json")
}
}
tasks.withType<JavaCompile> {
options.encoding = "UTF-8"
options.release.set(17)
}
tasks.withType<KotlinCompile> {
kotlinOptions {
jvmTarget = "17"
}
}
java {
withSourcesJar()
}
tasks.jar {
from("LICENSE")
}
//Github publishing
task("github") {
dependsOn(tasks.remapJar)
group = "upload"
onlyIf { environment.containsKey("GITHUB_TOKEN") }
doLast {
val github = GitHub.connectUsingOAuth(environment["GITHUB_TOKEN"])
val repository = github.getRepository(environment["GITHUB_REPOSITORY"])
val releaseBuilder = GHReleaseBuilder(repository, version as String)
releaseBuilder.name(releaseName)
releaseBuilder.body(getChangeLog())
releaseBuilder.commitish(getBranch())
val ghRelease = releaseBuilder.create()
ghRelease.uploadAsset(file(releaseFile), "application/java-archive")
}
}
//Curseforge publishing
curseforge {
environment["CURSEFORGE_API_KEY"]?.let { apiKey = it }
project(closureOf<CurseProject> {
id = project["curseforge_id"]
changelog = getChangeLog()
releaseType = this@Build_gradle.releaseType.toLowerCase()
addGameVersion(cfGameVersion)
addGameVersion("Fabric")
mainArtifact(file(releaseFile), closureOf<CurseArtifact> {
displayName = releaseName
relations(closureOf<CurseRelation> {
requiredDependency("fabric-api")
requiredDependency("fabric-language-kotlin")
})
})
afterEvaluate {
uploadTask.dependsOn("remapJar")
}
})
options(closureOf<Options> {
forgeGradleIntegration = false
})
}
//Modrinth publishing
task<TaskModrinthUpload>("modrinth") {
dependsOn(tasks.remapJar)
group = "upload"
onlyIf {
environment.containsKey("MODRINTH_TOKEN")
}
token = environment["MODRINTH_TOKEN"]
projectId = project["modrinth_id"]
changelog = getChangeLog()
versionNumber = version as String
versionName = releaseName
versionType = VersionType.valueOf(releaseType)
uploadFile = file(releaseFile)
addGameVersion(project["minecraft_version"])
addLoader("fabric")
}