forked from SuperRicky14/TpaPlusPlus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle.kts
182 lines (150 loc) · 4.55 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
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import java.text.SimpleDateFormat
import java.util.*
plugins {
alias(libs.plugins.kotlin)
alias(libs.plugins.loom)
alias(libs.plugins.git.hooks)
alias(libs.plugins.detekt)
alias(libs.plugins.shadow)
`maven-publish`
}
val props = properties
val modId: String by project
val modName: String by project
val modVersion: String by project
val mavenGroup: String by project
val targetJavaVersion = 21
val javaVersion = JavaVersion.VERSION_21
version = "$modVersion${getVersionMetadata()}"
group = mavenGroup
repositories {
maven("https://maven.architectury.dev/")
maven("https://maven.nucleoid.xyz")
mavenLocal()
mavenCentral()
}
dependencies {
detektPlugins(libs.detekt)
minecraft(libs.minecraft)
mappings(variantOf(libs.yarn.mappings) { classifier("v2") })
modImplementation(libs.bundles.fabric)
modImplementation(libs.architectury)
// For debug
modImplementation(libs.bundles.konf)
modImplementation(libs.gson)
// For release
shadow(libs.bundles.konf)
shadow(libs.gson)
}
base {
archivesName.set(modName)
}
java {
toolchain.languageVersion = JavaLanguageVersion.of(targetJavaVersion)
sourceCompatibility = javaVersion
targetCompatibility = javaVersion
withSourcesJar()
}
loom {
splitEnvironmentSourceSets()
mods {
register("tpaplusplus") {
sourceSet("main")
sourceSet("client")
}
}
}
tasks {
processResources {
val minecraftVersion: String by project
val loaderVersion: String by project
val kotlinLoaderVersion: String by project
inputs.property("version", project.version)
inputs.property("minecraft_version", minecraftVersion)
inputs.property("loader_version", loaderVersion)
filteringCharset = "UTF-8"
filesMatching("fabric.mod.json") {
expand(
"version" to project.version,
"minecraft_version" to minecraftVersion,
"loader_version" to loaderVersion,
"kotlin_loader_version" to kotlinLoaderVersion
)
}
}
withType<JavaCompile>().configureEach {
options.encoding = "UTF-8"
options.release.set(targetJavaVersion)
}
withType<KotlinCompile>().configureEach {
compilerOptions.jvmTarget.set(JvmTarget.fromTarget(targetJavaVersion.toString()))
}
jar {
from("LICENSE")
manifest {
attributes(
"Build-By" to System.getProperty("user.name"),
"Build-TimeStamp" to SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ").format(Date()),
"Build-Version" to version,
"Created-By" to "Gradle ${gradle.gradleVersion}",
"Build-Jdk" to "${System.getProperty("java.version")} " +
"(${System.getProperty("java.vendor")} ${System.getProperty("java.vm.version")})",
"Build-OS" to "${System.getProperty("os.name")} " +
"${System.getProperty("os.arch")} ${System.getProperty("os.version")}"
)
}
}
shadowJar {
from("LICENSE")
configurations = listOf(
project.configurations.shadow.get()
)
archiveClassifier.set("dev-all")
exclude("kotlin/**", "kotlinx/**", "javax/**")
exclude("org/intellij/**", "org/jetbrains/annotations/**")
exclude("org/slf4j/**")
exclude("net/kyori/**")
exclude("org/slf4j/**")
val relocatePath = "net.superricky.tpaplusplus.libs."
relocate("com.moandjiezana.toml", relocatePath + "com.moandjiezana.toml")
}
remapJar {
dependsOn(shadowJar)
inputFile = shadowJar.get().archiveFile
}
}
publishing {
publications {
create<MavenPublication>("mavenJava") {
artifactId = modName
from(components["java"])
}
}
repositories {
}
}
detekt {
buildUponDefaultConfig = true
autoCorrect = true
config.setFrom(rootProject.files("detekt.yml"))
}
gitHooks {
setHooks(
mapOf("pre-commit" to "detekt")
)
}
fun getVersionMetadata(): String {
val buildId = System.getenv("GITHUB_RUN_NUMBER")
val workflow = System.getenv("GITHUB_WORKFLOW")
if (workflow == "Release") {
return ""
}
// CI builds only
if (buildId != null) {
return "+build.$buildId"
}
// No tracking information could be found about the build
return "+nightly"
}