-
Notifications
You must be signed in to change notification settings - Fork 23
/
build.gradle.kts
166 lines (139 loc) · 4.72 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
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
import net.fabricmc.loom.api.LoomGradleExtensionAPI
import net.fabricmc.loom.task.RemapJarTask
plugins {
java
alias(libs.plugins.architectury)
alias(libs.plugins.loom) apply false
alias(libs.plugins.shadow) apply false
alias(libs.plugins.spotless)
}
val modId: String by project
val modVersion: String by project
val mavenGroup: String by project
val enabledPlatforms: String by project
val minecraftVersion: String = libs.versions.minecraft.get()
fun getGitRef(): String {
return providers.exec {
commandLine("git", "rev-parse", "--short", "HEAD")
isIgnoreExitValue = true
}.standardOutput.asText.get().trim()
}
subprojects {
apply(plugin = "java")
apply(plugin = rootProject.libs.plugins.architectury.get().pluginId)
apply(plugin = rootProject.libs.plugins.loom.get().pluginId)
version = "${modVersion}+${getGitRef()}"
group = mavenGroup
base.archivesName.set("${modId}-MC${minecraftVersion}-${project.name}")
architectury {
minecraft = minecraftVersion
}
configure<LoomGradleExtensionAPI> {
silentMojangMappingsLicense()
}
repositories {
exclusiveContent {
forRepository { maven("https://maven.parchmentmc.org") }
filter { includeGroupByRegex("org\\.parchmentmc.*") }
}
exclusiveContent {
forRepository { maven("https://api.modrinth.com/maven") }
filter { includeGroup("maven.modrinth") }
}
}
dependencies {
"minecraft"(rootProject.libs.minecraft)
val loom = project.extensions.getByName<LoomGradleExtensionAPI>("loom")
"mappings"(loom.layered {
officialMojangMappings()
parchment("org.parchmentmc.data:parchment-${rootProject.libs.versions.parchment.minecraft.get()}:${rootProject.libs.versions.parchment.mappings.get()}@zip")
})
"compileOnly"("com.google.code.findbugs:jsr305:3.0.2")
}
java {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
tasks {
jar {
from("LICENSE") {
rename { "${it}_${modId}" }
}
}
withType<JavaCompile>().configureEach {
options.encoding = "utf-8"
options.release.set(17)
}
}
idea {
module {
for (exclude in arrayOf("out", "logs")) {
excludeDirs.add(file(exclude))
}
}
}
}
val projectConfigurations = mapOf(
"fabric" to "Fabric",
"forge" to "Forge",
"neoforge" to "NeoForge"
)
for (platform in enabledPlatforms.split(',')) {
project(":$platform") {
apply(plugin = rootProject.libs.plugins.shadow.get().pluginId)
architectury {
platformSetupLoomIde()
loader(platform)
}
val common: Configuration by configurations.creating
val shadowBundle: Configuration by configurations.creating
configurations {
common.isCanBeResolved = true
common.isCanBeConsumed = false
compileClasspath.get().extendsFrom(common)
runtimeClasspath.get().extendsFrom(common)
getByName("development${projectConfigurations[platform]}").extendsFrom(common)
shadowBundle.isCanBeResolved = true
shadowBundle.isCanBeConsumed = false
}
dependencies {
common(project(path = ":common", configuration = "namedElements")) { isTransitive = false }
shadowBundle(
project(
path = ":common",
configuration = "transformProduction${projectConfigurations[platform]}"
)
) { isTransitive = false }
}
tasks {
withType<ShadowJar> {
exclude("architectury.common.json")
configurations = listOf(shadowBundle)
archiveClassifier.set("dev-shadow")
}
withType<RemapJarTask> {
val shadowJarTask = getByName<ShadowJar>("shadowJar")
inputFile.set(shadowJarTask.archiveFile)
dependsOn(shadowJarTask)
archiveClassifier.set(null as String?)
}
jar {
archiveClassifier.set("dev")
}
}
(components["java"] as AdhocComponentWithVariants)
.withVariantsFromConfiguration(configurations["shadowRuntimeElements"]) {
skip()
}
}
}
spotless {
java {
target("*/src/*/java/li/cil/**/*.java")
endWithNewline()
trimTrailingWhitespace()
removeUnusedImports()
indentWithSpaces()
}
}