Skip to content

Commit

Permalink
Use gradle.properties for platform name instead of functions
Browse files Browse the repository at this point in the history
  • Loading branch information
object-Object committed May 28, 2024
1 parent 567bde1 commit 1b1995d
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 57 deletions.
2 changes: 1 addition & 1 deletion templates/1.20.1/build.gradle.kts.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ architectury {

tasks {
register("runAllDatagen") {
dependsOn(":Forge:runCommonDatagen")
dependsOn(":{{ forge_path }}:runCommonDatagen")
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,74 +10,38 @@ plugins {
id("me.modmuss50.mod-publish-plugin")
}

// plugin config

abstract class {{ base_classname }}PlatformExtension(private val project: Project) {
abstract val developmentConfiguration: Property<String>
abstract val shadowCommonConfiguration: Property<String>

fun platform(platform: String, vararg extraModLoaders: String) = project.run {
// "inheritance" (ie. call the minecraft plugin's platform method so consumers don't have to do it)
val minecraftExtension = extensions.getByType<I{{ base_classname }}MinecraftExtension>()
minecraftExtension.platform(platform)

platform.replaceFirstChar(Char::uppercase).also {
developmentConfiguration.convention("development$it")
shadowCommonConfiguration.convention("transformProduction$it")
}

configurations {
named(developmentConfiguration.get()) {
extendsFrom(get("common"))
}
}

dependencies {
"shadowCommon"(project(":{{ common_path }}", shadowCommonConfiguration.get())) { isTransitive = false }
}

publishMods {
modLoaders.addAll(platform, *extraModLoaders)
displayName = modLoaders.map { values ->
val loaders = values.joinToString(", ") { it.replaceFirstChar(Char::uppercase) }
// CurseForge/Modrinth version display name (eg. "v0.1.0 [Fabric, Quilt]")
"v${project.version} [$loaders]"
}
}
}
}

val extension = extensions.create<{{ base_classname }}PlatformExtension>("{{ base_classname|lower }}Platform")

// build logic

val platform: String by project
val curseforgeId: String by project
val modrinthId: String by project

val minecraftVersion = libs.versions.minecraft.get()

val isCI = (System.getenv("CI") ?: "").isNotBlank()
val isDryRun = (System.getenv("DRY_RUN") ?: "").isNotBlank()
val curseforgeToken = System.getenv("CURSEFORGE_TOKEN") ?: ""
val modrinthToken = System.getenv("MODRINTH_TOKEN") ?: ""
val platformCapitalized = platform.capitalize()

architectury {
platformSetupLoomIde()
}

configurations {
val common = register("common")
register("common")
register("shadowCommon")
compileClasspath {
extendsFrom(common)
extendsFrom(get("common"))
}
runtimeClasspath {
extendsFrom(common)
extendsFrom(get("common"))
}
// this needs to wait until Loom has been configured
afterEvaluate {
named("development$platformCapitalized") {
extendsFrom(get("common"))
}
}
}

dependencies {
"common"(project(":{{ common_path }}", "namedElements")) { isTransitive = false }
"shadowCommon"(project(":{{ common_path }}", "transformProduction$platformCapitalized")) { isTransitive = false }
}

sourceSets {
Expand Down Expand Up @@ -121,22 +85,32 @@ components {
}

publishMods {
val isCI = (System.getenv("CI") ?: "").isNotBlank()
val isDryRun = (System.getenv("DRY_RUN") ?: "").isNotBlank()
dryRun = !isCI || isDryRun

type = BETA
changelog = provider { getLatestChangelog() }
file = tasks.remapJar.flatMap { it.archiveFile }

modLoaders.add(platform)

displayName = modLoaders.map { values ->
val loaders = values.joinToString(", ") { it.capitalize() }
// CurseForge/Modrinth version display name (eg. "v0.1.0 [Fabric, Quilt]")
"v${project.version} [$loaders]"
}

curseforge {
accessToken = curseforgeToken
accessToken = System.getenv("CURSEFORGE_TOKEN") ?: ""
projectId = curseforgeId
minecraftVersions.add(minecraftVersion)
clientRequired = true
serverRequired = true
}

modrinth {
accessToken = modrinthToken
accessToken = System.getenv("MODRINTH_TOKEN") ?: ""
projectId = modrinthId
minecraftVersions.add(minecraftVersion)
}
Expand All @@ -151,3 +125,5 @@ fun getLatestChangelog() = rootProject.file("CHANGELOG.md").useLines { lines ->
.joinToString("\n") { it.value }
.trim()
}

fun String.capitalize() = replaceFirstChar(Char::uppercase)

0 comments on commit 1b1995d

Please sign in to comment.