Skip to content

Commit

Permalink
Move to stonecutter to support 1.20.1 as well as 1.20.4
Browse files Browse the repository at this point in the history
  • Loading branch information
isXander committed Apr 5, 2024
1 parent 26f52f2 commit 6fff473
Show file tree
Hide file tree
Showing 15 changed files with 306 additions and 159 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/.idea
/.gradle
/build
.gradle
build
/run
!*/.gitkeep
/.fleet
306 changes: 186 additions & 120 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,172 +1,222 @@
plugins {
java
alias(libs.plugins.kotlin.jvm)
alias(libs.plugins.kotlin.plugin.serialization)
kotlin("jvm") version "1.9.23"
kotlin("plugin.serialization") version "1.9.23"

alias(libs.plugins.loom)
id("fabric-loom") version "1.6.+"

id("com.modrinth.minotaur") version "2.7.+"
id("me.hypherionmc.cursegradle") version "2.+"
id("com.github.breadmoirai.github-release") version "2.4.+"
id("me.modmuss50.mod-publish-plugin") version "0.5.+"
`maven-publish`

id("io.github.p03w.machete") version "2.0.+"
id("io.github.p03w.machete") version "2.+"
id("org.ajoberstar.grgit") version "5.0.+"
}

val mcVersion = stonecutter.current.version
val mcDep = property("fmj.mcDep").toString()

group = "dev.isxander"
version = "2.13.2"
val versionWithoutMC = "2.14.0"
version = "$versionWithoutMC+${stonecutter.current.project}"
val isAlpha = "alpha" in version.toString()
val isBeta = "beta" in version.toString()

base {
archivesName.set(property("modName").toString())
}

stonecutter.expression {
when (it) {
"controlify" -> isPropDefined("deps.controlify")
"mod-menu" -> isPropDefined("deps.modMenu")
else -> null
}
}

loom {
if (stonecutter.current.isActive) {
runConfigs.all {
ideConfigGenerated(true)
runDir("../../run")
}
}

mixin {
useLegacyMixinAp.set(false)
}
}

repositories {
mavenCentral()
maven("https://maven.terraformersmc.com")
maven("https://maven.isxander.dev/releases")
maven("https://maven.isxander.dev/snapshots")
maven("https://maven.shedaniel.me/")
maven("https://maven.terraformersmc.com/releases")
maven("https://jitpack.io")
maven("https://api.modrinth.com/maven")
maven("https://maven.quiltmc.org/repository/release/")
maven("https://maven.quiltmc.org/repository/release")
maven("https://oss.sonatype.org/content/repositories/snapshots/")
maven("https://api.modrinth.com/maven") {
content {
includeGroup("maven.modrinth")
}
}
}

dependencies {
minecraft(libs.minecraft)
minecraft("com.mojang:minecraft:$mcVersion")

mappings(loom.layered {
val quiltMappings = libs.versions.quilt.mappings.get()
if (quiltMappings != "0")
mappings("org.quiltmc:quilt-mappings:${libs.versions.minecraft.get()}+build.$quiltMappings:intermediary-v2")
optionalProp("deps.quiltMappings") {
mappings("org.quiltmc:quilt-mappings:$mcVersion+build.$it:intermediary-v2")
}
officialMojangMappings()
})
modImplementation(libs.fabric.loader)
modImplementation(libs.fabric.api)
modImplementation(libs.fabric.language.kotlin)
modImplementation("net.fabricmc:fabric-loader:${property("deps.fabricLoader")}")

implementation(libs.ktoml.core)
include(libs.ktoml.core)

modApi(libs.yet.another.config.lib)
val fapiVersion = property("deps.fabricApi").toString()
listOf(
"fabric-resource-loader-v0",
"fabric-lifecycle-events-v1",
"fabric-key-binding-api-v1",
"fabric-command-api-v2",
).forEach {
modImplementation(fabricApi.module(it, fapiVersion))
}
modRuntimeOnly("net.fabricmc.fabric-api:fabric-api:$fapiVersion")
modImplementation("net.fabricmc:fabric-language-kotlin:${property("deps.flk")}")

implementation(libs.bundles.settxi)
include(libs.bundles.settxi)
modApi("dev.isxander.yacl:yet-another-config-lib-fabric:${property("deps.yacl")}") {
exclude(group = "net.fabricmc.fabric-api", module = "fabric-api")
}

modImplementation(libs.mod.menu)
optionalProp("deps.modMenu") {
modImplementation("com.terraformersmc:modmenu:$it")
}

modImplementation(libs.controlify)
optionalProp("deps.controlify") {
modImplementation("dev.isxander:controlify:$it")
}

libs.mixin.extras.let {
implementation(it)
annotationProcessor(it)
include(it)
listOf(
"settxi-core",
"settxi-kotlinx-serialization"
).forEach {
implementation("dev.isxander.settxi:$it:${property("deps.settxi")}")
include("dev.isxander.settxi:$it:${property("deps.settxi")}")
}

implementation("com.akuleshov7:ktoml-core-jvm:${property("deps.ktoml")}")
}

java {
withSourcesJar()
withJavadocJar()
}

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

withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
kotlinOptions {
jvmTarget = "17"
processResources {
val props = mutableMapOf(
"id" to findProperty("modId"),
"group" to project.group,
"name" to findProperty("modName"),
"description" to findProperty("modDescription"),
"version" to project.version,
"github" to findProperty("githubProject"),
"mc" to mcDep
)
optionalProp("fmj.yaclDep") {
props["yacl"] = it
}
}

processResources {
inputs.property("version", project.version)
props.forEach(inputs::property)

filesMatching("fabric.mod.json") {
expand(
"version" to project.version
)
expand(props)
}
}

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

dependsOn("modrinth")
dependsOn("modrinthSyncBody")
dependsOn("curseforge")
dependsOn("githubRelease")
dependsOn("publishMods")
dependsOn("publish")
}
}

val changelogText = file("changelogs/${project.version}.md").takeIf { it.exists() }?.readText() ?: "No changelog provided"

val modrinthId: String by project
if (modrinthId.isNotEmpty()) {
modrinth {
token.set(findProperty("modrinth.token")?.toString())
projectId.set(modrinthId)
versionNumber.set("${project.version}")
versionType.set("release")
uploadFile.set(tasks["remapJar"])
gameVersions.set(listOf("1.20.3", "1.20.2"))
loaders.set(listOf("fabric", "quilt"))
changelog.set(changelogText)
syncBodyFrom.set(file("README.md").readText())
dependencies {
required.project("fabric-api")
required.project("fabric-language-kotlin")
required.project("yacl")
optional.project("modmenu")
}
}
machete {
json.enabled.set(false)
}

val curseforgeId: String by project
if (hasProperty("curseforge.token") && curseforgeId.isNotEmpty()) {
curseforge {
apiKey = findProperty("curseforge.token")
project(closureOf<me.hypherionmc.cursegradle.CurseProject> {
mainArtifact(tasks["remapJar"], closureOf<me.hypherionmc.cursegradle.CurseArtifact> {
displayName = "${project.version}"
})

id = curseforgeId
releaseType = "release"
addGameVersion("1.20.3")
addGameVersion("1.20.2")
addGameVersion("Fabric")
addGameVersion("Quilt")
addGameVersion("Java 17")

relations(closureOf<me.hypherionmc.cursegradle.CurseRelation> {
requiredDependency("fabric-api")
requiredDependency("fabric-language-kotlin")
requiredDependency("yacl")
optionalDependency("modmenu")
})

changelog = changelogText
changelogType = "markdown"
})

options(closureOf<me.hypherionmc.cursegradle.Options> {
forgeGradleIntegration = false
})
publishMods {
displayName.set("Zoomify $versionWithoutMC for MC $mcVersion")
file.set(tasks.remapJar.get().archiveFile)
changelog.set(
rootProject.file("changelogs/${versionWithoutMC}.md")
.takeIf { it.exists() }
?.readText()
?: "No changelog provided."
)
type.set(when {
isAlpha -> ALPHA
isBeta -> BETA
else -> STABLE
})
modLoaders.add("fabric")

// modrinth and curseforge use different formats for snapshots. this can be expressed globally
val stableMCVersions = listOf(stonecutter.current.project)

val modrinthId: String by project
if (modrinthId.isNotBlank() && hasProperty("modrinth.token")) {
modrinth {
projectId.set(modrinthId)
accessToken.set(findProperty("modrinth.token")?.toString())
minecraftVersions.addAll(stableMCVersions)

requires { slug.set("fabric-api") }
requires { slug.set("yacl") }
optional { slug.set("modmenu") }
optional { slug.set("controlify") }
}

tasks.getByName("publishModrinth") {
dependsOn("optimizeOutputsOfRemapJar")
}
}
}

githubRelease {
token(findProperty("github.token")?.toString())
val curseforgeId: String by project
if (curseforgeId.isNotBlank() && hasProperty("curseforge.token")) {
curseforge {
projectId.set(curseforgeId)
accessToken.set(findProperty("curseforge.token")?.toString())
minecraftVersions.addAll(stableMCVersions)

requires { slug.set("fabric-api") }
requires { slug.set("yacl") }
optional { slug.set("modmenu") }
optional { slug.set("controlify") }
}

tasks.getByName("publishCurseforge") {
dependsOn("optimizeOutputsOfRemapJar")
}
}

val githubProject: String by project
val split = githubProject.split("/")
owner(split[0])
repo(split[1])
tagName("${project.version}")
targetCommitish("1.20")
body(changelogText)
releaseAssets(tasks["remapJar"].outputs.files)
if (githubProject.isNotBlank() && hasProperty("github.token")) {
github {
repository.set(githubProject)
accessToken.set(findProperty("github.token")?.toString())
commitish.set(grgit.branch.current().name)
}

tasks.getByName("publishGithub") {
dependsOn("optimizeOutputsOfRemapJar")
}
}
}

publishing {
publications {
register<MavenPublication>("zoomify") {
create<MavenPublication>("mod") {
groupId = "dev.isxander"
artifactId = "zoomify"

Expand All @@ -175,17 +225,33 @@ publishing {
}

repositories {
if (hasProperty("XANDER_MAVEN_USER") && hasProperty("XANDER_MAVEN_PASS")) {
maven("https://maven.isxander.dev/releases") {
val username = "XANDER_MAVEN_USER".let { System.getenv(it) ?: findProperty(it) }?.toString()
val password = "XANDER_MAVEN_PASS".let { System.getenv(it) ?: findProperty(it) }?.toString()
if (username != null && password != null) {
maven(url = "https://maven.isxander.dev/releases") {
name = "XanderReleases"
credentials {
username = findProperty("XANDER_MAVEN_USER")?.toString()
password = findProperty("XANDER_MAVEN_PASS")?.toString()
this.username = username
this.password = password
}
}
} else println("Cannot publish to https://maven.isxander.dev")
tasks.getByName("publishModPublicationToXanderReleasesRepository") {
dependsOn("optimizeOutputsOfRemapJar")
}
} else {
println("Xander Maven credentials not satisfied.")
}
}
}

tasks["githubRelease"].dependsOn("optimizeOutputsOfRemapJar")
tasks["modrinth"].dependsOn("optimizeOutputsOfRemapJar")
tasks["generateMetadataFileForZoomifyPublication"].dependsOn("optimizeOutputsOfRemapJar")
tasks.getByName("generateMetadataFileForModPublication") {
dependsOn("optimizeOutputsOfRemapJar")
}

fun <T> optionalProp(property: String, block: (String) -> T?) {
findProperty(property)?.toString()?.takeUnless { it.isBlank() }?.let(block)
}

fun isPropDefined(property: String): Boolean {
return property(property)?.toString()?.isNotBlank() ?: false
}
9 changes: 9 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,12 @@ systemProp.kotlinVersion=1.8.0
modrinthId=zoomify
curseforgeId=574741
githubProject=isXander/Zoomify

modId=zoomify
modName=Zoomify
modDescription=An advanced zoom key.

deps.fabricLoader=0.15.9
deps.flk=1.10.19+kotlin.1.9.23
deps.settxi=2.10.6
deps.ktoml=0.5.1
Loading

0 comments on commit 6fff473

Please sign in to comment.