Skip to content

Commit 975bf72

Browse files
committed
Finish configuring dependencies
1 parent bc58a7f commit 975bf72

File tree

5 files changed

+102
-61
lines changed

5 files changed

+102
-61
lines changed

Fabric/build.gradle.kts

Lines changed: 17 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,23 @@ hexdebugPlatform {
1515
hexdebugModDependencies {
1616
filesMatching.add("fabric.mod.json")
1717

18-
versions = versions.get().mapValues { (_, version) ->
19-
version
20-
.replace(",", " ")
21-
.replace(Regex("""\s+"""), " ")
22-
.replace(Regex("""\[(\S+)"""), ">=$1")
23-
.replace(Regex("""(\S+)\]"""), "<=$1")
24-
.replace(Regex("""\](\S+)"""), ">$1")
25-
.replace(Regex("""(\S+)\["""), "<$1")
18+
anyVersion = "*"
19+
mapVersions {
20+
replace(",", " ")
21+
replace(Regex("""\s+"""), " ")
22+
replace(Regex("""\[(\S+)"""), ">=$1")
23+
replace(Regex("""(\S+)\]"""), "<=$1")
24+
replace(Regex("""\](\S+)"""), ">$1")
25+
replace(Regex("""(\S+)\["""), "<$1")
2626
}
27+
28+
requires("architectury-api")
29+
requires("cloth-config")
30+
requires(curseforge = "hexcasting", modrinth = "hex-casting")
31+
32+
requires("fabric-api")
33+
requires("fabric-language-kotlin")
34+
requires("modmenu")
2735
}
2836

2937
repositories {
@@ -50,6 +58,7 @@ dependencies {
5058
modImplementation(libs.cardinalComponents)
5159
modImplementation(libs.serializationHooks)
5260
modImplementation(libs.trinkets)
61+
5362
implementation(libs.mixinExtras)
5463

5564
modApi(libs.clothConfig.fabric) {
@@ -65,44 +74,3 @@ dependencies {
6574
include(libs.bundles.lsp4j)
6675
include(libs.ktor.network)
6776
}
68-
69-
publishMods {
70-
// Uncomment your desired platform(s)
71-
// curseforge {
72-
// accessToken = project.curseforgeApiToken
73-
// projectId = project.curseforgeID
74-
// minecraftVersions.add(minecraftVersion)
75-
//
76-
// requires{
77-
// slug = "fabric-debugger"
78-
// }
79-
// requires {
80-
// slug = "architectury-debugger"
81-
// }
82-
// requires {
83-
// slug = "fabric-language-kotlin"
84-
// }
85-
// requires {
86-
// slug = "hexcasting"
87-
// }
88-
// }
89-
//
90-
// modrinth {
91-
// accessToken = project.modrinthApiToken
92-
// projectId = project.modrinthID
93-
// minecraftVersions.add("1.19.2")
94-
//
95-
// requires{
96-
// slug = "fabric-debugger"
97-
// }
98-
// requires {
99-
// slug = "architectury-debugger"
100-
// }
101-
// requires {
102-
// slug = "fabric-language-kotlin"
103-
// }
104-
// requires {
105-
// slug = "hex-casting"
106-
// }
107-
// }
108-
}

Forge/build.gradle.kts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,18 @@ hexdebugPlatform {
3939

4040
hexdebugModDependencies {
4141
filesMatching.add("META-INF/mods.toml")
42+
43+
anyVersion = ""
44+
mapVersions {
45+
replace(Regex("""\](\S+)"""), "($1")
46+
replace(Regex("""(\S+)\["""), "$1)")
47+
}
48+
49+
requires("architectury-api")
50+
requires("cloth-config")
51+
requires(curseforge = "hexcasting", modrinth = "hex-casting")
52+
53+
requires("kotlin-for-forge")
4254
}
4355

4456
dependencies {
@@ -54,9 +66,11 @@ dependencies {
5466

5567
modApi(libs.clothConfig.forge)
5668

69+
implementation(libs.mixinExtras)
5770
implementation(libs.bundles.lsp4j)
5871
implementation(libs.bundles.ktor)
5972

73+
include(libs.mixinExtras)
6074
include(libs.bundles.lsp4j)
6175
include(libs.bundles.ktor)
6276

Forge/src/main/resources/META-INF/mods.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,13 @@ versionRange = "[${versions.architectury},)"
3333
ordering = "NONE"
3434
side = "BOTH"
3535

36+
[[dependencies.hexdebug]]
37+
modId = "cloth_config"
38+
mandatory = true
39+
versionRange = "[${versions.cloth_config},)"
40+
ordering = "NONE"
41+
side = "BOTH"
42+
3643
[[dependencies.hexdebug]]
3744
modId = "hexcasting"
3845
mandatory = true

plugins/src/main/kotlin/hexdebug/conventions/platform.gradle.kts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,8 @@ publishMods {
127127
accessToken = envOrEmpty("CURSEFORGE_TOKEN")
128128
projectId = hexdebugProperties.curseforgeId
129129
minecraftVersions.add(hexdebugProperties.minecraftVersion)
130+
clientRequired = true
131+
serverRequired = true
130132
}
131133

132134
modrinth {

plugins/src/main/kotlin/hexdebug/utils/mod-dependencies.gradle.kts

Lines changed: 62 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,71 @@
11
package hexdebug.utils
22

3+
plugins {
4+
id("me.modmuss50.mod-publish-plugin")
5+
}
6+
37
// plugin config
48

5-
interface HexDebugModDependenciesExtension {
6-
val filesMatching: ListProperty<String>
7-
val versions: MapProperty<String, String>
8-
}
9+
abstract class HexDebugModDependenciesExtension(private val project: Project) {
10+
private val versionCatalog by lazy {
11+
project.extensions.getByType<VersionCatalogsExtension>().named("libs")
12+
}
913

10-
val extension = extensions.create<HexDebugModDependenciesExtension>("hexdebugModDependencies")
14+
abstract val filesMatching: ListProperty<String>
15+
abstract val anyVersion: Property<String>
16+
abstract val mapVersions: Property<VersionMapper.() -> Unit>
17+
18+
fun mapVersions(action: VersionMapper.() -> Unit) {
19+
mapVersions = action
20+
}
21+
22+
fun getVersions(): Map<String, String> = versionCatalog.versionAliases.associate {
23+
val mapper = VersionMapper(
24+
name = it.replace(".", "_"),
25+
constraint = versionCatalog.findVersion(it).get(),
26+
)
27+
mapVersions.get().invoke(mapper)
28+
mapper.name to (mapper.version ?: anyVersion.get())
29+
}
1130

12-
val versionCatalog = extensions.getByType<VersionCatalogsExtension>().named("libs")
13-
extension.versions.convention(provider {
14-
versionCatalog.versionAliases.associate {
15-
// both "." and "-" cause issues with expand :/
16-
it.replace(".", "_") to versionCatalog.findVersion(it).get().requiredVersion
31+
fun requires(slug: String) = requires(slug, slug)
32+
fun requires(curseforge: String, modrinth: String) = dependency(curseforge, modrinth, true)
33+
34+
fun optional(slug: String) = optional(slug, slug)
35+
fun optional(curseforge: String, modrinth: String) = dependency(curseforge, modrinth, false)
36+
37+
fun dependency(
38+
curseforge: String,
39+
modrinth: String,
40+
required: Boolean = true,
41+
) {
42+
project.publishMods {
43+
curseforge {
44+
if (required) requires(curseforge) else optional(curseforge)
45+
}
46+
modrinth {
47+
if (required) requires(modrinth) else optional(modrinth)
48+
}
49+
}
1750
}
18-
})
51+
52+
data class VersionMapper(
53+
val name: String,
54+
val constraint: VersionConstraint,
55+
) {
56+
var version: String? = constraint.requiredVersion.takeIf { it.isNotEmpty() }
57+
58+
fun replace(old: String, new: String) {
59+
version = version?.replace(old, new)
60+
}
61+
62+
fun replace(old: Regex, new: String) {
63+
version = version?.replace(old, new)
64+
}
65+
}
66+
}
67+
68+
val extension = extensions.create<HexDebugModDependenciesExtension>("hexdebugModDependencies")
1969

2070
// build logic
2171

@@ -25,7 +75,7 @@ tasks.withType<ProcessResources>().configureEach {
2575
// allow referencing values from libs.versions.toml in Fabric/Forge mod configs
2676
val dependencyVersions = mapOf(
2777
"modVersion" to modVersion,
28-
"versions" to extension.versions.get(),
78+
"versions" to extension.getVersions(),
2979
)
3080

3181
// for incremental builds

0 commit comments

Comments
 (0)