-
Notifications
You must be signed in to change notification settings - Fork 21
/
build.gradle.kts
158 lines (137 loc) · 5.82 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
@file:Suppress("PublicApiImplicitType", "UnstableApiUsage")
import java.util.*
// loom expects the decompiler to be in the buildscript classpath. However, it seems that applying the plugin in
// buildSrc scripts means loom isn't properly in the buildscript classpath.
buildscript {
repositories {
maven {
name = "Fabric"
url = uri("https://maven.fabricmc.net/")
}
jcenter()
mavenCentral()
gradlePluginPortal()
}
dependencies {
// update this to match version in buildSrc
classpath("net.fabricmc:fabric-loom:0.10.64")
}
}
plugins {
`attribute-conventions`
`minecraft-conventions`
}
apply<CommonConfigPlugin>()
allprojects {
repositories {
mavenLocal()
jcenter()
mavenCentral()
// OSSRH, just in case a version hasn't synced to central yet
maven("https://s01.oss.sonatype.org/content/repositories/releases/")
maven("https://jitpack.io")
maven("https://www.cursemaven.com") {
content { includeGroup("curse.maven") }
}
maven("https://repo.spongepowered.org/repository/maven-public/")
maven("https://storage.googleapis.com/devan-maven/") // for ARRP
maven("https://maven.terraformersmc.com/releases") // for ModMenu
}
}
commonConfig {
val snapshotVersion = System.getenv("SNAPSHOT_REF")?.let { ref ->
if(!ref.startsWith("refs/heads/"))
throw IllegalStateException("SNAPSHOT_REF `$ref` doesn't start with refs/heads/")
val branch = ref.removePrefix("refs/heads/")
branch.replace("[^.\\w-]".toRegex(), "-") + "-SNAPSHOT"
}
val mod_version: String by project
version = snapshotVersion ?: mod_version
modules {
subprojects.forEach {
if(it.name !in setOf("testcore", "runtime", "dist"))
create(it.name)
}
}
}
loom {
runConfigs.configureEach {
isIdeConfigGenerated = false
}
}
tasks.configureEach {
if(name == "remapAllJars")
dependsOn(":remapJar")
}
// ---------------------------------------------------------------------------------------------------------------------
//region // Utilities
open class CreateModule: CopyFreemarker() {
@Option(option = "name", description = "The name of the module in Title Case. e.g. 'Cool Thing'. " +
"The PascalCase and lowercase names will be inferred from this")
var moduleName: Property<String> = project.objects.property()
@Option(option = "desc", description = "The description of the module. e.g. 'Automatic Cool object generation'")
var moduleDescription: Property<String> = project.objects.property()
val humanName: String get() = moduleName.get()
val pascalName: String get() = humanName.replace(" ", "")
val camelName: String get() = pascalName.substring(0, 1).toLowerCase(Locale.ROOT) + pascalName.substring(1)
val lowerName: String get() = pascalName.toLowerCase(Locale.ROOT)
}
// use `./gradlew createModule --name=Whatever`
tasks.register<CreateModule>("createModule") {
template.set(project.file("modules/_template"))
outputDirectory.set(project.file("modules"))
model {
"humanName" %= humanName
"PascalName" %= pascalName
"camelName" %= camelName
"lowername" %= lowerName
"description" %= moduleDescription.get()
}
doFirst {
val moduleDirectory = outputDirectory.get().resolve(lowerName)
if(moduleDirectory.exists())
throw IllegalArgumentException("Target directory `$moduleDirectory` already exists")
}
doLast {
logger.warn("############################################################################")
logger.warn("# Some manual actions are still required when adding a module! #")
logger.warn("# - Set the maven_description in the new module's gradle.properties #")
logger.warn("# - Add `includeModule(\"$lowerName\")` to the settings.gradle.kts file #")
logger.warn("# - Add `create(\"$lowerName\")` to the root build.gradle.kts commonConfig #")
logger.warn("# - Add an item describing the module in the root README.md file. e.g. #")
logger.warn("- `$lowerName` – ${moduleDescription.get()}")
logger.warn("############################################################################")
}
}
val updateReadmeVersions = tasks.register<ReplaceTextInPlace>("updateReadmeVersions") {
fun formatBadge(id: String, label: String, message: String, color: String, alt: String): String {
val cleanLabel = label.replace("_", "__").replace("-", "--").replace(" ", "_")
val cleanMessage = message.replace("_", "__").replace("-", "--").replace(" ", "_")
return """<img id="$id" src="https://img.shields.io/badge/$cleanLabel-$cleanMessage-$color" alt="$alt"/>"""
}
val minecraft_version: String by project
val mod_version: String by project
replaceIn("README.md") {
add("""<img id="([^"]*-badge)".*?/>""".toRegex()) { _, match ->
when (match.group(1)) {
"mod-version-badge" -> formatBadge(
id = "mod-version-badge",
label = "LibrarianLib",
message = mod_version,
color = "blue",
alt = "LibrarianLib $mod_version"
)
"mc-version-badge" -> formatBadge(
id = "mc-version-badge",
label = "Minecraft",
message = minecraft_version,
color = "blue",
alt = "Minecraft $minecraft_version"
)
else -> match.group()
}
}
}
}
//endregion // Utilities
// ---------------------------------------------------------------------------------------------------------------------