Skip to content

Commit

Permalink
do something
Browse files Browse the repository at this point in the history
  • Loading branch information
rhysdh540 committed Jun 4, 2024
1 parent a835b66 commit 7a7703d
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 42 deletions.
73 changes: 49 additions & 24 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
@file:Suppress("UnstableApiUsage")

import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
import xyz.wagyourtail.unimined.api.minecraft.task.RemapJarTask
import xyz.wagyourtail.unimined.util.sourceSets

plugins {
id("java")
id("xyz.wagyourtail.unimined")
id("io.github.pacifistmc.forgix")
id("com.github.johnrengelman.shadow")
}
try {
Git.repository = rootDir.toPath()
} catch(_: IllegalStateException) {
}

setup()

Expand Down Expand Up @@ -54,6 +52,10 @@ allprojects {
options.encoding = "UTF-8"
options.release = 17
options.compilerArgs.addAll(listOf("-Xplugin:Manifold no-bootstrap", "-implicit:none"))

javaCompiler = javaToolchains.compilerFor {
languageVersion.set(JavaLanguageVersion.of(17))
}
}

tasks.withType<AbstractArchiveTask> {
Expand All @@ -68,6 +70,8 @@ allprojects {
mojmap()
parchment(version = "parchment_version"())
}

defaultRemapJar = false
}

tasks.withType<RemapJarTask> {
Expand All @@ -82,6 +86,7 @@ allprojects {
annotationProcessor(this)
}
compileOnly("dev.architectury:architectury-injectables:${"arch_injectables_version"()}")
compileOnly("io.github.llamalad7:mixinextras-common:${"mixin_extras_version"()}")
}
}

Expand All @@ -107,10 +112,27 @@ subprojects {
source(rootProject.sourceSets["main"].allSource)
}

val common by configurations.registering {
isTransitive = false
}

dependencies {
implementation(rootProject).apply {
(this as ModuleDependency).isTransitive = false
}
common(rootProject)
}

tasks.shadowJar {
archiveBaseName.set("archives_base_name"())
archiveVersion.set("modVersion"())
archiveClassifier.set(project.name)

configurations = listOf(common.get())

relocate("dev.rdh.createunlimited.${project.name}", "dev.rdh.createunlimited.platform")
relocate("dev.rdh.createunlimited", "dev.rdh.createunlimited.${project.name}")
}

unimined.minecraft(sourceSet = sourceSets["main"], lateApply = true) {
remap(tasks.shadowJar.get())
}
}

Expand Down Expand Up @@ -140,7 +162,21 @@ dependencies {
"modImplementation"("com.simibubi.create:create-fabric-${"minecraft_version"()}:${"create_fabric_version"()}+mc${"minecraft_version"()}") {
exclude(group = "com.github.llamalad7.mixinextras", module = "mixinextras-fabric")
}
compileOnly("io.github.llamalad7:mixinextras-common:${"mixin_extras_version"()}")
}

val mergeJars = tasks.register<ShadowJar>("mergeJars") {
group = "build"
description = "Merges the platform shadow jars into a single jar"
archiveBaseName.set("archives_base_name"())
archiveVersion.set("modVersion"())
subprojects.map { it.tasks["remapShadowJar"] }.forEach {
dependsOn(it)
from(it)
}
}

tasks.assemble {
dependsOn(mergeJars)
}

fun setup() {
Expand All @@ -151,10 +187,10 @@ fun setup() {
println("Build #$buildNumber")
}
println()
println("Current branch: ${Git.currentBranch()}")
println("Current commit: ${Git.hash()}")
if(Git.isDirty()) {
var changes = Git.getUncommitedChanges().split("\n").toMutableList()
println("Current branch: ${git.currentBranch()}")
println("Current commit: ${git.hash()}")
if(git.isDirty()) {
var changes = git.getUncommitedChanges().split("\n").toMutableList()
val maxChanges = 10
if(changes.size > maxChanges) {
changes = changes.subList(0, maxChanges)
Expand All @@ -169,21 +205,10 @@ fun setup() {

ext["modVersion"] = "mod_version"() + (buildNumber?.let { "-build.$it" } ?: "")

forgix {
group = "maven_group"()
mergedJarName = "${"archives_base_name"()}-${"modVersion"()}.jar"
outputDir = "build/libs"
}

tasks.mergeJars {
dependsOn("assemble")
}

tasks.assemble {
subprojects.forEach {
this.dependsOn(it.tasks.named("assemble"))
}
finalizedBy("mergeJars")
}

findAndLoadProperties()
Expand Down
10 changes: 0 additions & 10 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,4 @@ dependencies {

plugin(id = "xyz.wagyourtail.unimined", version = "unimined_version"())
plugin(id = "com.github.johnrengelman.shadow", version = "shadow_version"())
plugin(id = "io.github.pacifistmc.forgix", version = "forgix_version"())
}

gradlePlugin {
plugins {
create("budget-architectury") {
id = "budget-architectury"
implementationClass = "BudgetArchPlugin"
}
}
}
14 changes: 7 additions & 7 deletions buildSrc/src/main/kotlin/Git.kt
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import xyz.wagyourtail.unimined.util.FinalizeOnWrite
import xyz.wagyourtail.unimined.util.MustSet
import java.nio.file.Path
import org.gradle.api.Project
import java.io.File

object Git {
val Project.git
get() = Git(rootProject.rootDir)

class Git(val repository: File) {
// does the current git repository have uncommitted changes?
fun isDirty() = git("status", "--porcelain").isNotBlank()

Expand All @@ -19,10 +21,8 @@ object Git {

private fun git(vararg args: String): String {
val process = ProcessBuilder("git", *args)
.directory(repository.toFile())
.directory(repository)
.start()
return process.inputStream.bufferedReader().readText()
}

var repository by FinalizeOnWrite<Path>(MustSet())
}
4 changes: 3 additions & 1 deletion forge/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ dependencies {
modImplementation("com.simibubi.create:create-${"minecraft_version"()}:${"create_forge_version"()}:slim") { isTransitive = false }
modImplementation("com.tterrag.registrate:Registrate:${"registrate_version"()}")
modImplementation("com.jozufozu.flywheel:flywheel-forge-${"flywheel_mc_version"()}:${"flywheel_version"()}")
implementation("io.github.llamalad7:mixinextras-forge:${"mixin_extras_version"()}") // TODO jarjar this
implementation("io.github.llamalad7:mixinextras-forge:${"mixin_extras_version"()}") {
"include"(this)
}
}

operator fun String.invoke(): String = rootProject.ext[this] as? String ?: error("Property $this is not defined")

0 comments on commit 7a7703d

Please sign in to comment.