Skip to content

Commit

Permalink
setup multiversion structure
Browse files Browse the repository at this point in the history
  • Loading branch information
btwonion committed Sep 12, 2024
1 parent f0d367f commit 636dbef
Show file tree
Hide file tree
Showing 32 changed files with 622 additions and 57 deletions.
196 changes: 151 additions & 45 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,84 +1,179 @@
@file:Suppress("SpellCheckingInspection", "UnstableApiUsage", "RedundantNullableReturnType")

import net.fabricmc.loom.util.ModPlatform
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import kotlin.io.path.readText

plugins {
kotlin("jvm") version "2.0.10"
kotlin("plugin.serialization") version "2.0.10"
id("fabric-loom") version "1.7-SNAPSHOT"
id("com.github.breadmoirai.github-release") version "2.5.2"
alias(libs.plugins.kotlin)
alias(libs.plugins.kotlinx.serialization)
alias(libs.plugins.architectury.loom)
alias(libs.plugins.mod.publish)

`maven-publish`
}

group = "dev.nyon"
val mcVersion = "1.20.4"
version = "2.0.2-$mcVersion"
val loader = loom.platform.get()
val isFabric = loader == ModPlatform.FABRIC

val beta: Int = property("mod.beta").toString().toInt()
val majorVersion: String = property("mod.major-version").toString()
val mcVersion = property("vers.mcVersion").toString() // Pattern is '1.0.0-beta1-1.20.6-pre.2+fabric'
version = "$majorVersion${if (beta != 0) "-beta$beta" else ""}-$mcVersion+${loader.name.lowercase()}"

group = property("mod.group").toString()
val githubRepo = property("mod.repo").toString()

base {
archivesName.set(rootProject.name)
}

val mixinsFile = property("mod.mixins").toString()
loom {
if (stonecutter.current.isActive) {
runConfigs.all {
ideConfigGenerated(true)
runDir("../../run")
}
}

if (loader == ModPlatform.FORGE) forge {
mixinConfigs(mixinsFile)
}

mixin { useLegacyMixinAp = false }
silentMojangMappingsLicense()
}

repositories {
mavenCentral()
maven("https://maven.parchmentmc.org")
maven("https://maven.quiltmc.org/repository/release/")
maven("https://repo.nyon.dev/releases")
maven("https://thedarkcolour.github.io/KotlinForForge/")
maven("https://maven.neoforged.net/releases/")
}

val flk: String = "${libs.versions.fabric.language.kotlin.orNull}${libs.versions.kotlin.orNull}"
dependencies {
minecraft("com.mojang:minecraft:$mcVersion")
mappings(
loom.layered {
parchment("org.parchmentmc.data:parchment-1.20.3:2023.12.31@zip")
officialMojangMappings()
}
)
implementation("org.vineflower:vineflower:1.9.3")
implementation("net.fabricmc:fabric-loader:0.15.11")

implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.7.1")
mappings(loom.layered {
val quiltMappings: String = property("vers.deps.quiltmappings").toString()
if (quiltMappings.isNotEmpty()) mappings("org.quiltmc:quilt-mappings:$quiltMappings:intermediary-v2")
officialMojangMappings()
})

implementation(libs.vineflower)

if (isFabric) {
implementation(libs.fabric.loader)
modImplementation("net.fabricmc:fabric-language-kotlin:$flk")
} else {
if (loader == ModPlatform.FORGE) {
"forge"("net.minecraftforge:forge:$mcVersion-${property("vers.deps.fml")}")
compileOnly(libs.mixinextras.common)
annotationProcessor(libs.mixinextras.common)
include(libs.mixinextras.forge)
implementation(libs.mixinextras.forge)
} else
"neoForge"("net.neoforged:neoforge:${property("vers.deps.fml")}")
if (hasProperty("vers.deps.kff")) implementation("thedarkcolour:kotlinforforge${if (loader == ModPlatform.NEOFORGE) "-neoforge" else ""}:${property("vers.deps.kff")}")
}

testImplementation(kotlin("test"))
modImplementation(libs.konfig)
include(libs.konfig)
}

val javaVersion = if (stonecutter.compare(mcVersion, "1.20.4") > 0) 21 else 17
val modId = property("mod.id").toString()
val modName = property("mod.name").toString()
val modDescription = property("mod.description").toString()
val mcVersionRange = property("vers.mcVersionRange").toString()
val icon = property("mod.icon").toString()
val slug = property("mod.slug").toString()
tasks {
register("release") {
processResources {
val props: Map<String, String?> = mapOf(
"id" to modId,
"name" to modName,
"description" to modDescription,
"version" to project.version.toString(),
"github" to githubRepo,
"mc" to mcVersionRange,
"flk" to if (!isFabric) null else flk,
"repo" to githubRepo,
"icon" to icon,
"mixins" to mixinsFile,
"slug" to slug
).filterNot { it.value == null }

props.forEach(inputs::property)

(if (isFabric) listOf("fabric.mod.json") else listOf(
"META-INF/mods.toml",
"META-INF/neoforge.mods.toml"
)).forEach { filesMatching(it) { expand(props) } }

filesMatching("pack.mcmeta") {
if (isFabric) exclude()
}
}

register("releaseMod") {
group = "publishing"

dependsOn("githubRelease")
dependsOn("publishMods")
dependsOn("publish")
}

withType<JavaCompile> {
options.release.set(17)
options.release = javaVersion
}

withType<KotlinCompile> {
compilerOptions {
jvmTarget = JvmTarget.JVM_17
jvmTarget = JvmTarget.fromTarget(javaVersion.toString())
}
}
}

kotlin {
sourceSets.all {
languageSettings {
optIn("dev.nyon.konfig.internal.InternalKonfigApi")
}
}
val changelogText = buildString {
append("# v${project.version}\n")
if (beta != 0) appendLine("### As this is still a beta version, this version can contain bugs. Feel free to report ANY misbehaviours and errors!")
rootDir.resolve("changelog.md").readText().also(::append)
}

val changelogText =
buildString {
append("# v${project.version}\n")
file("changelog.md").readText().also { append(it) }
val supportedMcVersions: List<String> =
property("vers.supportedMcVersions")!!.toString().split(',').map(String::trim).filter(String::isNotEmpty)

publishMods {
displayName = "v${project.version}"
file = tasks.remapJar.get().archiveFile
changelog = changelogText
type = if (beta != 0) BETA else STABLE
when (loader) {
ModPlatform.FABRIC -> modLoaders.addAll("fabric", "quilt")
ModPlatform.FORGE -> modLoaders.addAll("forge")
ModPlatform.NEOFORGE -> modLoaders.addAll("neoforge")
else -> {}
}

githubRelease {
token(providers.environmentVariable("GITHUB_TOKEN"))
modrinth {
// TODO project id
projectId = ""
accessToken = providers.environmentVariable("MODRINTH_API_KEY")
minecraftVersions.addAll(supportedMcVersions)

if (isFabric)
requires { slug = "fabric-language-kotlin" }
else
requires { slug = "kotlin-for-forge" }
}

owner = "btwonion"
repo = "konfig"
releaseName = project.version.toString()
tagName = project.version.toString()
body = changelogText
targetCommitish = "master"
setReleaseAssets(tasks["remapJar"].outputs.files)
github {
repository = githubRepo
accessToken = providers.environmentVariable("GITHUB_TOKEN")
commitish = property("mod.main-branch").toString()
}
}

publishing {
Expand All @@ -95,14 +190,25 @@ publishing {
publications {
create<MavenPublication>("maven") {
groupId = "dev.nyon"
artifactId = "konfig"
artifactId = modName
version = project.version.toString()
from(components["java"])
}
}
}

java {
withJavadocJar()
withSourcesJar()

val gradleJavaVersion = JavaVersion.toVersion(javaVersion)
sourceCompatibility = gradleJavaVersion
targetCompatibility = gradleJavaVersion
}

kotlin {
sourceSets.all {
languageSettings {
optIn("dev.nyon.konfig.internal.InternalKonfigApi")
}
}
}
18 changes: 17 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,18 @@
kotlin.code.style=official
org.gradle.jvmargs=-Xmx4096M
org.gradle.jvmargs=-Xmx4096M

mod.main-branch=master
mod.color=23959
# TODO: icon
mod.icon=
mod.icon-url=
mod.group=dev.nyon
mod.repo=btwonion/konfig
mod.slug=konfig
mod.id=konfig
mod.name=konfig
mod.description=Just a simple konfig library.. k for Kotlin
mod.beta=1
mod.major-version=2.0.2
mod.mixins=konfig.mixins.json
mod.supported-loaders=fabric,quilt,neoforge,forge
22 changes: 22 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[versions]
kotlin = "2.0.20"
mod-publish = "0.5.+"
architectury-loom = "1.7-SNAPSHOT"
fabric-loader = "0.16.4"
fabric-language-kotlin = "1.12.1+kotlin."
vineflower = "1.10.1"
konfig = "2.0.2-1.20.4"
mixinextras = "0.4.1"

[libraries]
vineflower = { module = "org.vineflower:vineflower", version.ref = "vineflower" }
konfig = { module = "dev.nyon:konfig", version.ref = "konfig" }
fabric-loader = { module = "net.fabricmc:fabric-loader", version.ref = "fabric-loader" }
mixinextras-common = { module = "io.github.llamalad7:mixinextras-common", version.ref = "mixinextras" }
mixinextras-forge = { module = "io.github.llamalad7:mixinextras-forge", version.ref = "mixinextras" }

[plugins]
kotlin = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }
kotlinx-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" }
architectury-loom = { id = "dev.architectury.loom", version.ref = "architectury-loom" }
mod-publish = { id = "me.modmuss50.mod-publish-plugin", version.ref = "mod-publish" }
6 changes: 4 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.1-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
zipStorePath=wrapper/dists
44 changes: 43 additions & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,9 +1,51 @@
import dev.kikugie.stonecutter.StonecutterSettings

rootProject.name = "konfig"

pluginManagement {
repositories {
mavenCentral()
gradlePluginPortal()
maven("https://maven.fabricmc.net/")
maven("https://maven.architectury.dev")
maven("https://maven.minecraftforge.net")
maven("https://maven.neoforged.net/releases/")
maven("https://maven.kikugie.dev/releases")
}
}

rootProject.name = "konfig"
plugins {
id("dev.kikugie.stonecutter") version "0.4.+"
}

buildscript {
repositories { mavenCentral() }
dependencies {
classpath("org.jetbrains.kotlinx:kotlinx-serialization-json:1.7.1")
}
}

extensions.configure<StonecutterSettings> {
kotlinController = true
centralScript = "build.gradle.kts"
shared {
vers("1.16.5-forge", "1.16.5")
vers("1.16.5-fabric", "1.16.5")
vers("1.18.2-forge", "1.18.2")
vers("1.18.2-fabric", "1.18.2")
vers("1.19.2-forge", "1.19.2")
vers("1.19.2-fabric", "1.19.2")
vers("1.19.4-forge", "1.19.4")
vers("1.19.4-fabric", "1.19.4")
vers("1.20.1-forge", "1.20.1")
vers("1.20.1-fabric", "1.20.1")
vers("1.20.4-neoforge", "1.20.4")
vers("1.20.4-fabric", "1.20.4")
vers("1.20.6-neoforge", "1.20.6")
vers("1.20.6-fabric", "1.20.6")
vers("1.21-neoforge", "1.21")
vers("1.21-fabric", "1.21")
vcsVersion = "1.21-fabric"
}
create(rootProject)
}
11 changes: 11 additions & 0 deletions src/main/kotlin/dev/nyon/konfig/KonfigEntrypoint.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package dev.nyon.konfig

/*? if fabric {*/
fun main() {

}
/*?} else if neoforge {*/

/*?} else {*/

/*?}*/
Loading

0 comments on commit 636dbef

Please sign in to comment.