-
Notifications
You must be signed in to change notification settings - Fork 56
/
Copy pathbuild.gradle.kts
210 lines (174 loc) · 5.54 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
201
202
203
204
205
206
207
208
209
210
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
plugins {
alias(libs.plugins.kotlin)
alias(libs.plugins.loom)
alias(libs.plugins.detekt)
alias(libs.plugins.git.hooks)
`maven-publish`
}
val modId: String by project
val modName: String by project
val modVersion: String by project
val mavenGroup: String by project
base.archivesName.set(modId)
version = "$modVersion${getVersionMetadata()}"
group = mavenGroup
sourceSets {
create("testmod") {
runtimeClasspath += sourceSets["main"].runtimeClasspath
compileClasspath += sourceSets["main"].compileClasspath
}
}
loom {
//serverOnlyMinecraftJar()
runs {
create("testmodClient") {
client()
ideConfigGenerated(project.rootProject == project)
name("Networking Testmod (Client)")
source(sourceSets.getByName("testmod"))
}
}
}
fun DependencyHandlerScope.modImplementationAndInclude(dep: Any) {
modImplementation(dep)
include(dep)
}
repositories {
maven("https://maven.fabricmc.net/")
maven("https://maven.nucleoid.xyz/")
maven("https://jitpack.io")
maven("https://oss.sonatype.org/content/repositories/snapshots")
mavenCentral()
mavenLocal()
}
val includeImplementation: Configuration by configurations.creating {
configurations.implementation.configure { extendsFrom(this@creating) }
}
dependencies {
// To change the versions see the libs.versions.toml
// Fabric
minecraft(libs.minecraft)
mappings(variantOf(libs.yarn.mappings) { classifier("v2") })
modImplementation(libs.fabric.loader)
// Fabric API
modImplementation(libs.fabric.api)
// Permissions
modImplementationAndInclude(libs.fabric.permissions)
// Translations
modImplementationAndInclude(libs.translations)
// Kotlin
modImplementation(libs.fabric.kotlin)
// Database
includeImplementation(libs.exposed.core)
includeImplementation(libs.exposed.dao)
includeImplementation(libs.exposed.java.time)
includeImplementation(libs.exposed.jdbc)
includeImplementation(libs.exposed.migration)
includeImplementation(libs.sqlite.jdbc)
// Config
includeImplementation(libs.konf.core)
includeImplementation(libs.konf.toml)
detektPlugins(libs.detekt.formatting)
}
tasks {
processResources {
inputs.property("id", modId)
inputs.property("name", modName)
inputs.property("version", version)
filesMatching("fabric.mod.json") {
expand(
mapOf(
"id" to modId,
"version" to version,
"name" to modName,
"fabricApi" to libs.versions.fabric.api.get(),
"fabricKotlin" to libs.versions.fabric.kotlin.get(),
"minecraft" to libs.versions.minecraft.get(),
)
)
}
}
jar {
from("LICENSE")
}
}
java {
sourceCompatibility = JavaVersion.VERSION_21
targetCompatibility = JavaVersion.VERSION_21
withSourcesJar()
}
kotlin {
compilerOptions {
jvmTarget.set(JvmTarget.JVM_21)
}
}
// configure the maven publication
publishing {
publications {
create<MavenPublication>("mavenJava") {
from(components["java"])
}
}
// select the repositories you want to publish to
repositories {
// mavenLocal()
}
}
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 "+local"
}
afterEvaluate {
dependencies {
handleIncludes(includeImplementation)
}
}
/* Thanks to https://github.com/jakobkmar for original script */
fun DependencyHandlerScope.includeTransitive(
dependencies: Set<ResolvedDependency>,
minecraftLibs: Set<ResolvedDependency>,
kotlinDependency: ResolvedDependency,
checkedDependencies: MutableSet<ResolvedDependency> = HashSet()
) {
dependencies.forEach {
if (checkedDependencies.contains(it) || it.moduleGroup == "org.jetbrains.kotlin" || it.moduleGroup == "org.jetbrains.kotlinx") return@forEach
if (kotlinDependency.children.any { dep -> dep.name == it.name }) {
println("Skipping -> ${it.name} (already in fabric-language-kotlin)")
} else if (minecraftLibs.any { dep -> dep.moduleGroup == it.moduleGroup && dep.moduleName == it.moduleName }) {
println("Skipping -> ${it.name} (already in minecraft)")
} else {
include(it.name)
println("Including -> ${it.name}")
}
checkedDependencies += it
includeTransitive(it.children, minecraftLibs, kotlinDependency, checkedDependencies)
}
}
fun DependencyHandlerScope.handleIncludes(configuration: Configuration) {
includeTransitive(
configuration.resolvedConfiguration.firstLevelModuleDependencies,
configurations.minecraftLibraries.get().resolvedConfiguration.firstLevelModuleDependencies,
configurations.modImplementation.get().resolvedConfiguration.firstLevelModuleDependencies
.first { it.moduleGroup == "net.fabricmc" && it.moduleName == "fabric-language-kotlin" },
)
}