-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcommon.gradle.kts
More file actions
287 lines (239 loc) · 9.33 KB
/
common.gradle.kts
File metadata and controls
287 lines (239 loc) · 9.33 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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
import nl.javadude.gradle.plugins.license.header.HeaderDefinitionBuilder
import java.util.Calendar
plugins {
id("net.fabricmc.fabric-loom") version ("1.15-SNAPSHOT")
// https://github.com/ReplayMod/preprocessor
// https://github.com/Fallen-Breath/preprocessor
id("com.replaymod.preprocess") version ("c5abb4fb12")
// https://github.com/GradleUp/shadow
id("com.gradleup.shadow") version ("9.4.1")
// https://github.com/hierynomus/license-gradle-plugin
id("com.github.hierynomus.license") version ("0.16.1")
// https://github.com/firstdarkdev/modpublisher
id("com.hypherionmc.modutils.modpublisher") version ("2.2.1")
`maven-publish`
}
val properties = project.properties
val mcVersionNumber = properties["mcVersion"] as Int
val minecraftVersion = properties["minecraft_version"].toString()
val jitpack = System.getenv("JITPACK") == "true"
val releasing = System.getenv("BUILD_RELEASE") == "true"
repositories {
mavenCentral()
maven {
name = "Fabric"
url = uri("https://maven.fabricmc.net/")
content {
includeGroup("net.fabricmc")
}
}
maven {
name = "Fallen"
url = uri("https://maven.fallenbreath.me/releases") // Fallen orz
content {
includeGroup("me.fallenbreath")
}
}
}
dependencies {
// loom
minecraft("com.mojang:minecraft:${minecraftVersion}")
// fabric
implementation("net.fabricmc:fabric-loader:${properties["loader_version"]}")
//libs
include((implementation("me.fallenbreath:conditional-mixin-fabric:${properties["conditionalmixin_version"]}") as Dependency))
testImplementation("net.fabricmc:fabric-loader-junit:${properties["loader_version"]}")
}
val mixinConfigPath = "authlib-proxy-for-server.mixins.json"
val javaCompatibility = JavaVersion.VERSION_25
val mixinCompatibility = javaCompatibility
loom {
runConfigs.configureEach {
runDir = "../../run/${mcVersionNumber}"
vmArgs(listOf("-Dmixin.debug.export=true"))
}
runConfigs["server"].apply {
ideConfigGenerated(true)
}
}
preprocess {
patternAnnotation.set("com.ayakacraft.authlibproxyforserver.utils.preprocess.PreprocessPattern")
}
tasks.shadowJar {
configurations = listOf(project.configurations["shadow"])
exclude("META-INF")
archiveClassifier = "shadow"
}
tasks.withType<ShadowJar> {
enableAutoRelocation = true
relocationPrefix = "authlibproxyforserver.libs"
}
val modVersion = properties["mod_version"].toString()
var modVersionSuffix = ""
var artifactVersion = modVersion
var artifactVersionSuffix = ""
// detect github action environment variables
// https://docs.github.com/en/actions/learn-github-actions/environment-variables#default-environment-variables
if (!releasing) {
modVersionSuffix += "-SNAPSHOT"
artifactVersionSuffix = "-SNAPSHOT" // A non-release artifact is always a SNAPSHOT artifact
}
var fullModVersion = modVersion + modVersionSuffix
var fullProjectVersion: String
var fullArtifactVersion: String
// Example version values:
// project.mod_version 1.0.3 (the base mod version)
// modVersionSuffix +build.88 (use github action build number if possible)
// artifactVersionSuffix -SNAPSHOT
// fullModVersion 1.0.3+build.88 (the actual mod version to use in the mod)
// fullProjectVersion v1.0.3-mc1.15.2+build.88 (in build output jar name)
// fullArtifactVersion 1.0.3-mc1.15.2-SNAPSHOT (maven artifact version)
if (jitpack) {
// move mc version into archivesBaseName, so jitpack will be able to organize archives from multiple subprojects correctly
base.archivesName = "${properties["archives_base_name"]}-mc${minecraftVersion}"
fullProjectVersion = "v${modVersion}${modVersionSuffix}"
fullArtifactVersion = artifactVersion + artifactVersionSuffix
} else {
base.archivesName = properties["archives_base_name"].toString()
fullProjectVersion = "v${modVersion}-mc${minecraftVersion}${modVersionSuffix}"
fullArtifactVersion = "${modVersion}-mc${minecraftVersion}${artifactVersionSuffix}"
}
version = fullProjectVersion
// See https://youtrack.jetbrains.com/issue/IDEA-296490
// if IDEA complains about "Cannot resolve resource filtering of MatchingCopyAction" and you want to know why
tasks.processResources {
inputs.apply {
property("id", properties["mod_id"].toString())
property("name", properties["mod_name"].toString())
property("version", fullModVersion)
}
filesMatching("fabric.mod.json") {
expand(
mapOf(
"id" to properties["mod_id"],
"name" to properties["mod_name"],
"version" to fullModVersion,
"minecraft_dependency" to properties["minecraft_dependency"],
"loader_dependency" to properties["loader_dependency"]
)
)
}
filesMatching(mixinConfigPath) {
expand(mapOf("COMPATIBILITY_LEVEL" to "JAVA_${mixinCompatibility.majorVersion}"))
}
}
// ensure that the encoding is set to UTF-8, no matter what the system default is
// this fixes some edge cases with special characters not displaying correctly
// see http://yodaconditions.net/blog/fix-for-java-file-encoding-problems-with-gradle.html
tasks.withType<JavaCompile> {
options.encoding = "UTF-8"
options.compilerArgs.addAll(listOf("-Xlint:deprecation", "-Xlint:unchecked"))
if (javaCompatibility <= JavaVersion.VERSION_1_8) {
// suppressed "source/target value 8 is obsolete and will be removed in a future release"
options.compilerArgs.add("-Xlint:-options")
}
}
java {
sourceCompatibility = javaCompatibility
targetCompatibility = javaCompatibility
withSourcesJar()
}
tasks.jar {
dependsOn(tasks.shadowJar)
mustRunAfter(tasks.shadowJar)
from(zipTree(tasks.shadowJar.get().archiveFile))
duplicatesStrategy = DuplicatesStrategy.INCLUDE
inputs.property("archives_base_name", properties["archives_base_name"])
from(rootProject.file("LICENSE")) {
rename { "${it}_${properties["archives_base_name"]}" }
}
}
tasks.shadowJar {
inputs.property("archives_base_name", properties["archives_base_name"])
from(rootProject.file("LICENSE")) {
rename { "${it}_${properties["archives_base_name"]}" }
}
}
// https://github.com/hierynomus/license-gradle-plugin
license {
// use "gradle licenseFormat" to apply license headers
header = rootProject.file("HEADER")
include("**/*.java")
skipExistingHeaders = true
headerDefinition(
// ref: https://github.com/mathieucarbou/license-maven-plugin/blob/4c42374bb737378f5022a3a36849d5e23ac326ea/license-maven-plugin/src/main/java/com/mycila/maven/plugin/license/header/HeaderType.java#L48
// modification: add a newline at the end
HeaderDefinitionBuilder("SLASHSTAR_STYLE_NEWLINE")
.withFirstLine("/*")
.withBeforeEachLine(" * ")
.withEndLine(" */\n")
.withFirstLineDetectionDetectionPattern("(\\s|\\t)*/\\*.*$")
.withLastLineDetectionDetectionPattern(".*\\*/(\\s|\\t)*$")
.withNoBlankLines()
.multiline()
.noPadLines()
)
mapping("java", "SLASHSTAR_STYLE_NEWLINE")
ext {
set("name", properties["mod_name"].toString())
set("author", "Calboot")
set("year", Calendar.getInstance().get(Calendar.YEAR).toString())
}
}
tasks["classes"].dependsOn(tasks.licenseFormatMain)
tasks["testClasses"].dependsOn(tasks.licenseFormatTest)
val minecraftVersions = properties["game_versions"].toString().split("\n")
// https://github.com/firstdarkdev/modpublisher
publisher {
apiKeys {
modrinth(System.getenv("MODRINTH_TOKEN") ?: "unset")
curseforge(System.getenv("CURSEFORGE_TOKEN") ?: "unset")
github(System.getenv("GITHUB_TOKEN") ?: "unset")
}
// debug = true
if (properties["curseforge_id"] != null) {
curseID = properties["curseforge_id"].toString()
}
if (properties["modrinth_id"] != null) {
modrinthID = properties["modrinth_id"].toString()
}
versionType = properties["mod_version_type"].toString() // "alpha", "beta", "release"
changelog = rootProject.file("changelog.md")
projectVersion = fullProjectVersion
gameVersions = minecraftVersions
setLoaders("fabric")
setCurseEnvironment("server")
artifact.set(tasks.jar)
if (mcVersionNumber < 11700) {
setJavaVersions(JavaVersion.VERSION_1_8)
}
github {
repo(System.getenv("REPO"))
tag(System.getenv("TAG"))
}
}
// configure the maven publication
publishing {
publications {
create<MavenPublication>("maven") {
from(components["java"])
artifactId = base.archivesName.get()
version = fullArtifactVersion
}
}
// select the repositories you want to publish to
repositories {
maven {
name = "AyakaCraft"
url = uri("https://mc.ayakacraft.com:7000/releases")
credentials<PasswordCredentials>(PasswordCredentials::class) {
username = "Publisher"
password = System.getenv("AYAKA_MAVEN_TOKEN")
}
authentication {
create("basic", BasicAuthentication::class)
}
}
}
}