-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.gradle.kts
More file actions
142 lines (110 loc) · 4.95 KB
/
build.gradle.kts
File metadata and controls
142 lines (110 loc) · 4.95 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
import java.io.ByteArrayOutputStream
import java.time.LocalDateTime
import java.time.format.DateTimeFormatter
evaluationDependsOnChildren()
class Properties(project: Project) {
val version: String by project
val modName: String by project
val modDescription: String by project
val group: String by project
val modId: String by project
val license: String by project
val repo: String by project
val minMinecraft: String by project
val maxMinecraft: String by project
}
inline fun <reified T : Task> TaskContainer.configureFor(task: String, action: Action<T>) {
named<T>(task).configure(action)
}
fun ConfigurationContainer.findOrCreateDependencyScopeByName(name: String): Configuration {
return findByName(name) ?: dependencyScope(name).get()
}
val timestamp = LocalDateTime.now().format(DateTimeFormatter.ofPattern("MM.dd"))
subprojects {
val properties = Properties(rootProject)
val buildNum = providers.environmentVariable("GITHUB_RUN_NUMBER")
.filter(String::isNotEmpty)
.map { "build.$it" }
.orElse("local.$timestamp")
.get()
extensions.getByType<BasePluginExtension>().archivesName = properties.modId
group = properties.group
version = "${properties.version}+$buildNum-mc.${libs.versions.minecraft.get()}-$name"
val jarName = "${properties.modId}-${version}.jar"
extensions.getByType<JavaPluginExtension>().run {
toolchain.languageVersion = JavaLanguageVersion.of(21)
}
if (name == "common")
return@subprojects
tasks.named<ProcessResources>("processResources") {
val replace: Map<String, Any> = mapOf(
"mod_id" to properties.modId,
"group" to properties.group,
"mod_description" to properties.modDescription,
"mod_name" to properties.modName,
"version" to version,
"fabric_loader_version" to libs.versions.fabric.loader.get(),
"fabric_api_version" to libs.versions.fabric.api.get(),
"minecraft_version" to libs.versions.minecraft.get(),
"license" to properties.license,
"repo" to properties.repo,
"min_minecraft" to properties.minMinecraft,
"max_minecraft" to properties.maxMinecraft
)
inputs.properties(replace)
filesMatching(listOf("fabric.mod.json", "META-INF/neoforge.mods.toml")) {
expand(replace)
}
}
configurations.findByName("commonJava")
val commonJava = configurations.findOrCreateDependencyScopeByName("commonJava")
val commonResources = configurations.findOrCreateDependencyScopeByName("commonResources")
val clientCommonJava = configurations.findOrCreateDependencyScopeByName("clientCommonJava")
val clientCommonResources = configurations.findOrCreateDependencyScopeByName("clientCommonResources")
val compileOnly: Configuration = configurations.getByName("compileOnly")
val clientCompileOnly: Configuration = configurations.getByName("clientCompileOnly") {
extendsFrom(compileOnly)
}
dependencies {
compileOnly(project(":common"))
clientCompileOnly(project(":common"))
clientCompileOnly(project(":common", configuration="clientApiElements"))
commonJava(project(":common", configuration="commonJava"))
commonResources(project(":common", configuration="commonResources"))
clientCommonJava(project(":common", configuration="clientCommonJava"))
clientCommonResources(project(":common", configuration="clientCommonResources"))
}
val resolvableCommonJava: Configuration by configurations.resolvable("resolvableCommonJava") {
extendsFrom(commonJava)
}
val resolvableClientCommonJava: Configuration by configurations.resolvable("resolvableClientCommonJava") {
extendsFrom(clientCommonJava)
}
val resolvableCommonResources: Configuration by configurations.resolvable("resolvableCommonResources") {
extendsFrom(commonResources)
}
val resolvableClientCommonResources: Configuration by configurations.resolvable("resolvableClientCommonResources") {
extendsFrom(clientCommonResources)
}
tasks.configureFor<JavaCompile>("compileJava") {
dependsOn(resolvableCommonJava)
source(resolvableCommonJava)
}
tasks.configureFor<ProcessResources>("processResources") {
dependsOn(resolvableCommonResources)
from(resolvableCommonResources)
}
tasks.configureFor<JavaCompile>("compileClientJava") {
dependsOn(resolvableClientCommonJava)
source(resolvableClientCommonJava)
}
tasks.configureFor<ProcessResources>("processClientResources") {
dependsOn(resolvableClientCommonResources)
from(resolvableClientCommonResources)
}
tasks.register<Copy>("collect") {
from(project.layout.buildDirectory.file("libs/$jarName"))
into(rootProject.layout.buildDirectory.dir("libs/"))
}
tasks.findByName("assemble")?.finalizedBy("collect")
}