From 0dc8f97b73277cae8fe8d3a396fbe376fddb26f0 Mon Sep 17 00:00:00 2001 From: Jozufozu Date: Sun, 12 Jan 2025 16:08:38 -0800 Subject: [PATCH] String theory - Assume group/version are behind properties in subproject.init - Force each subproject to manually specify their base archive name - Don't generate mod/api artifact ids, just write them out by hand - Remove DependentProject --- .../gradle/platform/PlatformExtension.kt | 24 ++----------------- .../gradle/subproject/SubprojectExtension.kt | 12 +++++----- common/build.gradle.kts | 2 +- fabric/build.gradle.kts | 6 ++--- forge/build.gradle.kts | 6 ++--- vanillinFabric/build.gradle.kts | 5 ++-- vanillinForge/build.gradle.kts | 5 ++-- 7 files changed, 19 insertions(+), 41 deletions(-) diff --git a/buildSrc/src/main/kotlin/dev/engine_room/gradle/platform/PlatformExtension.kt b/buildSrc/src/main/kotlin/dev/engine_room/gradle/platform/PlatformExtension.kt index 76f1b175e..1c03dad14 100644 --- a/buildSrc/src/main/kotlin/dev/engine_room/gradle/platform/PlatformExtension.kt +++ b/buildSrc/src/main/kotlin/dev/engine_room/gradle/platform/PlatformExtension.kt @@ -13,15 +13,10 @@ import org.gradle.jvm.tasks.Jar import org.gradle.kotlin.dsl.* import org.gradle.language.jvm.tasks.ProcessResources import java.io.File -import kotlin.properties.ReadWriteProperty -import kotlin.reflect.KProperty +import kotlin.properties.Delegates open class PlatformExtension(val project: Project) { - var commonProject: Project by DependentProject(this.project) - - var modArtifactId: String = "flywheel-${project.name}-${project.property("artifact_minecraft_version")}" - - var apiArtifactId: String = "flywheel-${project.name}-api-${project.property("artifact_minecraft_version")}" + var commonProject: Project by Delegates.notNull() val commonSourceSets: SourceSetContainer by lazy { commonProject.the() } @@ -124,19 +119,4 @@ open class PlatformExtension(val project: Project) { } } } - - private class DependentProject(private val thisProject: Project) : ReadWriteProperty { - private var value: Project? = null - - override fun getValue(thisRef: Any?, property: KProperty<*>): Project { - return value ?: throw IllegalStateException("Property ${property.name} should be initialized before get.") - } - - override fun setValue(thisRef: Any?, property: KProperty<*>, value: Project) { - this.value = value - } - - override fun toString(): String = - "NotNullProperty(${if (value != null) "value=$value" else "value not initialized yet"})" - } } diff --git a/buildSrc/src/main/kotlin/dev/engine_room/gradle/subproject/SubprojectExtension.kt b/buildSrc/src/main/kotlin/dev/engine_room/gradle/subproject/SubprojectExtension.kt index 29e3f7690..223538724 100644 --- a/buildSrc/src/main/kotlin/dev/engine_room/gradle/subproject/SubprojectExtension.kt +++ b/buildSrc/src/main/kotlin/dev/engine_room/gradle/subproject/SubprojectExtension.kt @@ -16,8 +16,8 @@ import org.gradle.kotlin.dsl.* import org.gradle.language.jvm.tasks.ProcessResources open class SubprojectExtension(val project: Project) { - fun init(group: String, version: String) { - setBaseProperties(group, version) + fun init(archiveBase: String, group: String, version: String) { + setBaseProperties(archiveBase, group, version) setupJava() addRepositories() setupLoom() @@ -26,17 +26,17 @@ open class SubprojectExtension(val project: Project) { setupPublishing() } - private fun setBaseProperties(group: String, version: String) { + private fun setBaseProperties(archiveBase: String, group: String, version: String) { val dev = System.getenv("RELEASE")?.contentEquals("false", true) ?: true val buildNumber = System.getenv("BUILD_NUMBER") val versionSuffix = if (dev && buildNumber != null) "-${buildNumber}" else "" - project.group = group - project.version = "${version}${versionSuffix}" + project.group = project.property(group) as String + project.version = "${project.property(version)}${versionSuffix}" project.the().apply { - archivesName = "flywheel-${project.name}-${project.property("artifact_minecraft_version")}" + archivesName = "${archiveBase}-${project.property("artifact_minecraft_version")}" } } diff --git a/common/build.gradle.kts b/common/build.gradle.kts index af237a959..a2877f83b 100644 --- a/common/build.gradle.kts +++ b/common/build.gradle.kts @@ -6,7 +6,7 @@ plugins { id("flywheel.subproject") } -subproject.init(property("flywheel_group") as String, property("flywheel_version") as String) +subproject.init("flywheel-common", "flywheel_group", "flywheel_version") val api = sourceSets.create("api") val lib = sourceSets.create("lib") diff --git a/fabric/build.gradle.kts b/fabric/build.gradle.kts index 8392678c3..67b44b5a0 100644 --- a/fabric/build.gradle.kts +++ b/fabric/build.gradle.kts @@ -7,7 +7,7 @@ plugins { id("flywheel.platform") } -subproject.init(property("flywheel_group") as String, property("flywheel_version") as String) +subproject.init("flywheel-fabric", "flywheel_group", "flywheel_version") val api = sourceSets.create("api") val lib = sourceSets.create("lib") @@ -55,12 +55,12 @@ platform { } jarSets { - mainSet.publish(platform.modArtifactId) + mainSet.publish("flywheel-fabric-${project.property("artifact_minecraft_version")}") mainSet.outgoing("flywheel") create("api", api, lib).apply { addToAssemble() - publish(platform.apiArtifactId) + publish("flywheel-fabric-api-${project.property("artifact_minecraft_version")}") configureJar { manifest { diff --git a/forge/build.gradle.kts b/forge/build.gradle.kts index fb03838f2..a12ea2c76 100644 --- a/forge/build.gradle.kts +++ b/forge/build.gradle.kts @@ -7,7 +7,7 @@ plugins { id("flywheel.platform") } -subproject.init(property("flywheel_group") as String, property("flywheel_version") as String) +subproject.init("flywheel-forge", "flywheel_group", "flywheel_version") val api = sourceSets.create("api") val lib = sourceSets.create("lib") @@ -53,12 +53,12 @@ platform { } jarSets { - mainSet.publish(platform.modArtifactId) + mainSet.publish("flywheel-forge-${project.property("artifact_minecraft_version")}") mainSet.outgoing("flywheel") create("api", api, lib).apply { addToAssemble() - publish(platform.apiArtifactId) + publish("flywheel-forge-api-${project.property("artifact_minecraft_version")}") configureJar { manifest { diff --git a/vanillinFabric/build.gradle.kts b/vanillinFabric/build.gradle.kts index 3b59ceb16..96883fd3c 100644 --- a/vanillinFabric/build.gradle.kts +++ b/vanillinFabric/build.gradle.kts @@ -10,12 +10,11 @@ plugins { id("flywheel.platform") } -subproject.init(property("vanillin_group") as String, property("vanillin_version") as String) +subproject.init("vanillin-fabric", "vanillin_group", "vanillin_version") val main = sourceSets.getByName("main") platform { - modArtifactId = "vanillin-fabric-${project.property("artifact_minecraft_version")}" commonProject = project(":common") setupLoomRuns() } @@ -49,7 +48,7 @@ tasks.named(main.processResourcesTaskName).configure { } jarSets { - mainSet.publish(platform.modArtifactId) + mainSet.publish("vanillin-fabric-${project.property("artifact_minecraft_version")}") } defaultPackageInfos { diff --git a/vanillinForge/build.gradle.kts b/vanillinForge/build.gradle.kts index 26a7b2e30..e16475411 100644 --- a/vanillinForge/build.gradle.kts +++ b/vanillinForge/build.gradle.kts @@ -10,12 +10,11 @@ plugins { id("flywheel.platform") } -subproject.init(property("vanillin_group") as String, property("vanillin_version") as String) +subproject.init("vanillin-forge", "vanillin_group", "vanillin_version") val main = sourceSets.getByName("main") platform { - modArtifactId = "vanillin-forge-${project.property("artifact_minecraft_version")}" commonProject = project(":common") setupLoomRuns() } @@ -49,7 +48,7 @@ tasks.named(main.processResourcesTaskName).configure { } jarSets { - mainSet.publish(platform.modArtifactId) + mainSet.publish("vanillin-forge-${project.property("artifact_minecraft_version")}") } defaultPackageInfos {