-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathsettings.gradle
More file actions
155 lines (122 loc) · 4.51 KB
/
Copy pathsettings.gradle
File metadata and controls
155 lines (122 loc) · 4.51 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
import groovy.json.JsonSlurper
import java.util.regex.Matcher
import java.util.regex.Pattern
pluginManagement {
repositories {
mavenLocal()
maven {
name = "NyanMaven Mirror"
url = "https://maven.hendrixshen.moe/mirror"
}
maven {
name = "Jitpack"
url = "https://maven.hendrixshen.moe/jitpack"
content {
includeGroupAndSubgroups("com.github")
}
}
gradlePluginPortal()
}
resolutionStrategy {
eachPlugin {
switch (requested.id.id) {
case "com.replaymod.preprocess": {
useModule("com.github.Fallen-Breath:preprocessor:${requested.version}")
break
}
}
}
}
}
dependencyResolutionManagement {
versionCatalogs {
register("forges") {
from(files("./gradle/forges.versions.toml"))
}
register("mods") {
from(files("./gradle/mods.versions.toml"))
}
}
}
ext {
File localPropsFile = file("${rootDir}/local.properties")
if (localPropsFile.exists()) {
Properties p = new Properties()
p.load(new FileInputStream(localPropsFile))
p.each { key, value ->
ext[key as String] = value
}
}
getOrDefault = { String key, String defaultValue ->
if (!ext.has(key)) {
return defaultValue
}
String value = ext.getProperty(key)
return value.isEmpty() ? defaultValue : value
}
}
rootProject.setName(settings.providers.gradleProperty("mod.id").get())
includeBuild("build-logic")
// Magic Core API
["common", "fabric", "forge", "neoforge"].forEach {
include("magiclib-core:${it}")
}
// Magic Game API
Map<String, Map<String, ?>> settings = file("settings.json").withReader {
new JsonSlurper().parse(it) as Map<String, Map<String, ?>>
}
Map<String, Set<String>> wrappers = new HashMap<>()
for (String module_name : settings.get("projects").keySet()) {
Map<String, ?> project_detail = settings.get("projects").get(module_name) as Map<String, ?>
String prefix = project_detail.get("prefix")
List<String> versions = project_detail.get("versions") as List<String>
File mainProjectFile = file("${module_name}/versions/mainProject")
if (!mainProjectFile.exists()) {
throw new IllegalArgumentException("Missing mainProject file: ${mainProjectFile.absolutePath}")
}
String mainProject = new String(mainProjectFile.readBytes()).trim().replace("${prefix}-", "")
if (!versions.contains(mainProject)) {
throw new IllegalArgumentException("Invalid main project: ${mainProject}")
}
for (String ver : versions) {
Matcher matcher = Pattern.compile("^((?:0|[1-9]\\d*)\\.(?:0|[1-9]\\d*)(?:\\.(?:0|[1-9]\\d*))?(?:_\\w+)*)-(fabric|forge|neoforge|quilt)?\$").matcher(ver)
if (!matcher.matches()) {
throw new IllegalArgumentException("Invalid submodule name: ${ver}")
}
File project_dir = file("${module_name}/versions/${ver}")
if (!project_dir.exists()) {
if (!project_dir.mkdirs()) {
throw new IllegalArgumentException("Failed to create missing submodule directory: ${project_dir.absolutePath}")
}
logger.warn("Creating missing submodule directory: ${project_dir.absolutePath}")
}
String project_name = "${module_name}:${prefix}-${ver}"
include("${project_name}")
ProjectDescriptor proj = project(":${project_name}")
proj.setProjectDir(project_dir)
proj.setBuildFileName("../${mainProject}/build.gradle")
wrappers.computeIfAbsent(matcher.group(2), key -> new HashSet<>()).add(matcher.group(1))
}
}
for (String platform : wrappers.keySet()) {
for (String ver : wrappers.get(platform)) {
File file = file("magiclib-wrapper/${platform}/${ver}")
if (!file.exists()) {
file.mkdirs()
}
include("magiclib-wrapper:${platform}:${ver}")
}
}
logger.lifecycle("""
**************************************************
You are building MagicLib
Note:
1) You need to run 'gradlew preprocessResources'
before the first build or
after a clean build or the build will fail!
2) You can quickly control parts of the dev env
using the configuration file generated by
'gradlew genLocalProperties'.
Output files will be in magiclib-wrapper/[platform]/[mc_ver]/build/libs
**************************************************
""")