See yourself out

- Replace outgoing jars by directly consuming classes/resources from
  common
- Add vanillin logo
- Move subproject plugin logic to an extension so it can be configured
- Rename "mod_" properties to "flywheel_"
This commit is contained in:
Jozufozu 2025-01-12 14:04:21 -08:00
parent 6bea04ffee
commit b541c19785
19 changed files with 284 additions and 238 deletions

View file

@ -13,10 +13,6 @@ open class JarSetExtension(private val project: Project) {
return JarTaskSet.create(project, name, *sourceSetSet)
}
fun outgoing(name: String, vararg sourceSetSet: SourceSet): JarTaskSet {
return JarTaskSet.create(project, name, *sourceSetSet).also { it.createOutgoingConfiguration() }
}
val mainSet: JarTaskSet by lazy {
val jarTask = project.tasks.named<Jar>("jar")
val remapJarTask = project.tasks.named<RemapJarTask>("remapJar")

View file

@ -41,18 +41,6 @@ class JarTaskSet(
}
}
/**
* Create a new configuration that can be consumed by other projects, and export the base jar.
*/
fun createOutgoingConfiguration() {
val config = project.configurations.register(name) {
isCanBeConsumed = true
isCanBeResolved = false
}
project.artifacts.add(config.name, jar)
}
/**
* Configure the assemble task to depend on the remap tasks and javadoc jar.
*/

View file

@ -0,0 +1,182 @@
package dev.engine_room.gradle.subproject
import net.fabricmc.loom.api.LoomGradleExtensionAPI
import org.gradle.api.JavaVersion
import org.gradle.api.Project
import org.gradle.api.plugins.BasePluginExtension
import org.gradle.api.plugins.JavaPluginExtension
import org.gradle.api.publish.PublishingExtension
import org.gradle.api.publish.tasks.GenerateModuleMetadata
import org.gradle.api.tasks.bundling.AbstractArchiveTask
import org.gradle.api.tasks.compile.JavaCompile
import org.gradle.api.tasks.javadoc.Javadoc
import org.gradle.jvm.tasks.Jar
import org.gradle.jvm.toolchain.JavaLanguageVersion
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)
setupJava()
addRepositories()
setupLoom()
setupDependencies()
configureTasks()
setupPublishing()
}
private fun setBaseProperties(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.the<BasePluginExtension>().apply {
archivesName = "flywheel-${project.name}-${project.property("artifact_minecraft_version")}"
}
}
private fun setupLoom() {
val loom = project.the<LoomGradleExtensionAPI>()
loom.silentMojangMappingsLicense()
}
private fun setupJava() {
val java_version: String by project
project.the<JavaPluginExtension>().apply {
val javaVersion = JavaVersion.toVersion(java_version)
sourceCompatibility = javaVersion
targetCompatibility = javaVersion
toolchain.languageVersion = JavaLanguageVersion.of(java_version)
withSourcesJar()
withJavadocJar()
}
}
private fun addRepositories() {
project.repositories.apply {
mavenCentral()
maven("https://maven.parchmentmc.org") {
name = "ParchmentMC"
}
maven("https://maven.tterrag.com/") {
name = "tterrag maven"
}
maven("https://www.cursemaven.com") {
name = "CurseMaven"
content {
includeGroup("curse.maven")
}
}
maven("https://api.modrinth.com/maven") {
name = "Modrinth"
content {
includeGroup("maven.modrinth")
}
}
}
}
@Suppress("UnstableApiUsage")
private fun setupDependencies() {
project.dependencies.apply {
val minecraft_version: String by project
val parchment_minecraft_version: String by project
val parchment_version: String by project
val loom = project.the<LoomGradleExtensionAPI>()
add("minecraft", "com.mojang:minecraft:${minecraft_version}")
add("mappings", loom.layered {
officialMojangMappings()
parchment("org.parchmentmc.data:parchment-${parchment_minecraft_version}:${parchment_version}@zip")
})
add("api", "com.google.code.findbugs:jsr305:3.0.2")
}
}
private fun configureTasks() {
val java_version: String by project
project.tasks.apply {
// make builds reproducible
withType<AbstractArchiveTask>().configureEach {
isPreserveFileTimestamps = false
isReproducibleFileOrder = true
}
// module metadata is often broken on multi-platform projects
withType<GenerateModuleMetadata>().configureEach {
enabled = false
}
withType<JavaCompile>().configureEach {
options.encoding = "UTF-8"
options.release = Integer.parseInt(java_version)
options.compilerArgs.add("-Xdiags:verbose")
}
withType<Jar>().configureEach {
from("${project.rootDir}/LICENSE.md") {
into("META-INF")
}
}
withType<Javadoc>().configureEach {
options.optionFiles(project.rootProject.file("javadoc-options.txt"))
options.encoding = "UTF-8"
}
val replaceProperties = processResourcesExpandProperties.associateWith { project.property(it) as String }
withType<ProcessResources>().configureEach {
inputs.properties(replaceProperties)
filesMatching(processResourcesExpandFiles) {
expand(replaceProperties)
}
}
}
}
private fun setupPublishing() {
project.the<PublishingExtension>().repositories.apply {
maven("file://${project.rootProject.projectDir}/mcmodsrepo")
if (project.hasProperty("mavendir")) {
maven(project.rootProject.file(project.property("mavendir") as String))
}
}
}
}
val processResourcesExpandFiles = listOf("pack.mcmeta", "fabric.mod.json", "META-INF/mods.toml")
val processResourcesExpandProperties = listOf(
"mod_license",
"mod_sources",
"mod_issues",
"mod_homepage",
"flywheel_id",
"flywheel_name",
"flywheel_description",
"flywheel_version",
"vanillin_id",
"vanillin_name",
"vanillin_version",
"vanillin_description",
"flywheel_maven_version_range",
"flywheel_semver_version_range",
"minecraft_semver_version_range",
"minecraft_maven_version_range",
"fabric_api_version_range",
"forge_version_range",
)

View file

@ -3,189 +3,14 @@ package dev.engine_room.gradle.subproject
import dev.engine_room.gradle.jarset.JarSetExtension
import dev.engine_room.gradle.nullability.PackageInfosExtension
import dev.engine_room.gradle.transitive.TransitiveSourceSetsExtension
import net.fabricmc.loom.api.LoomGradleExtensionAPI
import org.gradle.api.JavaVersion
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.plugins.BasePluginExtension
import org.gradle.api.plugins.JavaPluginExtension
import org.gradle.api.publish.PublishingExtension
import org.gradle.api.publish.tasks.GenerateModuleMetadata
import org.gradle.api.tasks.bundling.AbstractArchiveTask
import org.gradle.api.tasks.compile.JavaCompile
import org.gradle.api.tasks.javadoc.Javadoc
import org.gradle.jvm.tasks.Jar
import org.gradle.jvm.toolchain.JavaLanguageVersion
import org.gradle.kotlin.dsl.*
import org.gradle.language.jvm.tasks.ProcessResources
class SubprojectPlugin: Plugin<Project> {
override fun apply(project: Project) {
project.extensions.create("defaultPackageInfos", PackageInfosExtension::class.java, project)
project.extensions.create("transitiveSourceSets", TransitiveSourceSetsExtension::class.java, project)
project.extensions.create("jarSets", JarSetExtension::class.java, project)
setBaseProperties(project)
setupJava(project)
addRepositories(project)
setupLoom(project)
setupDependencies(project)
configureTasks(project)
setupPublishing(project)
}
private fun setBaseProperties(project: Project) {
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 = project.property("group") as String
project.version = "${project.property("mod_version")}${versionSuffix}"
project.the<BasePluginExtension>().apply {
archivesName = "flywheel-${project.name}-${project.property("artifact_minecraft_version")}"
}
}
private fun setupLoom(project: Project) {
val loom = project.the<LoomGradleExtensionAPI>()
loom.silentMojangMappingsLicense()
}
private fun setupJava(project: Project) {
val java_version: String by project
project.the<JavaPluginExtension>().apply {
val javaVersion = JavaVersion.toVersion(java_version)
sourceCompatibility = javaVersion
targetCompatibility = javaVersion
toolchain.languageVersion = JavaLanguageVersion.of(java_version)
withSourcesJar()
withJavadocJar()
}
}
private fun addRepositories(project: Project) {
project.repositories.apply {
mavenCentral()
maven("https://maven.parchmentmc.org") {
name = "ParchmentMC"
}
maven("https://maven.tterrag.com/") {
name = "tterrag maven"
}
maven("https://www.cursemaven.com") {
name = "CurseMaven"
content {
includeGroup("curse.maven")
}
}
maven("https://api.modrinth.com/maven") {
name = "Modrinth"
content {
includeGroup("maven.modrinth")
}
}
}
}
@Suppress("UnstableApiUsage")
private fun setupDependencies(project: Project) {
project.dependencies.apply {
val minecraft_version: String by project
val parchment_minecraft_version: String by project
val parchment_version: String by project
val loom = project.the<LoomGradleExtensionAPI>()
add("minecraft", "com.mojang:minecraft:${minecraft_version}")
add("mappings", loom.layered {
officialMojangMappings()
parchment("org.parchmentmc.data:parchment-${parchment_minecraft_version}:${parchment_version}@zip")
})
add("api", "com.google.code.findbugs:jsr305:3.0.2")
}
}
private fun configureTasks(project: Project) {
val java_version: String by project
project.tasks.apply {
// make builds reproducible
withType<AbstractArchiveTask>().configureEach {
isPreserveFileTimestamps = false
isReproducibleFileOrder = true
}
// module metadata is often broken on multi-platform projects
withType<GenerateModuleMetadata>().configureEach {
enabled = false
}
withType<JavaCompile>().configureEach {
options.encoding = "UTF-8"
options.release = Integer.parseInt(java_version)
options.compilerArgs.add("-Xdiags:verbose")
}
withType<Jar>().configureEach {
from("${project.rootDir}/LICENSE.md") {
into("META-INF")
}
}
withType<Javadoc>().configureEach {
options.optionFiles(project.rootProject.file("javadoc-options.txt"))
options.encoding = "UTF-8"
}
val replaceProperties = processResourcesExpandProperties.associateWith { project.property(it) as String }
withType<ProcessResources>().configureEach {
inputs.properties(replaceProperties)
filesMatching(processResourcesExpandFiles) {
expand(replaceProperties)
}
}
}
}
private fun setupPublishing(project: Project) {
project.the<PublishingExtension>().repositories.apply {
maven("file://${project.rootProject.projectDir}/mcmodsrepo")
if (project.hasProperty("mavendir")) {
maven(project.rootProject.file(project.property("mavendir") as String))
}
}
project.extensions.create("subproject", SubprojectExtension::class.java, project)
}
}
val processResourcesExpandFiles = listOf("pack.mcmeta", "fabric.mod.json", "META-INF/mods.toml")
val processResourcesExpandProperties = listOf(
"mod_id",
"mod_name",
"mod_description",
"mod_license",
"mod_sources",
"mod_issues",
"mod_homepage",
"mod_version",
"minecraft_semver_version_range",
"minecraft_maven_version_range",
"fabric_api_version_range",
"forge_version_range",
"vanillin_id",
"vanillin_name",
"vanillin_version",
"vanillin_description",
"flywheel_maven_version_range",
"flywheel_semver_version_range",
)

View file

@ -1,6 +1,9 @@
package dev.engine_room.gradle.transitive
import org.gradle.api.tasks.SourceSet
import org.gradle.api.tasks.compile.JavaCompile
import org.gradle.kotlin.dsl.named
import org.gradle.language.jvm.tasks.ProcessResources
class TransitiveSourceSetConfigurator(private val parent: TransitiveSourceSetsExtension, private val sourceSet: SourceSet) {
internal val compileSourceSets = mutableSetOf<SourceSet>()
@ -37,4 +40,35 @@ class TransitiveSourceSetConfigurator(private val parent: TransitiveSourceSetsEx
compile(*sourceSets)
runtime(*sourceSets)
}
fun outgoing() {
outgoingClasses()
outgoingResources()
}
fun outgoingResources() {
val project = parent.project
val exportResources = project.configurations.register("${sourceSet.name}Resources") {
isCanBeResolved = false
isCanBeConsumed = true
}
val processResources = project.tasks.named<ProcessResources>(sourceSet.processResourcesTaskName).get()
project.artifacts.add(exportResources.name, processResources.destinationDir) {
builtBy(processResources)
}
}
fun outgoingClasses() {
val project = parent.project
val exportClasses = project.configurations.register("${sourceSet.name}Classes") {
isCanBeResolved = false
isCanBeConsumed = true
}
val compileTask = project.tasks.named<JavaCompile>(sourceSet.compileJavaTaskName).get()
project.artifacts.add(exportClasses.name, compileTask.destinationDirectory) {
builtBy(compileTask)
}
}
}

View file

@ -5,7 +5,7 @@ import org.gradle.api.Project
import org.gradle.api.file.FileCollection
import org.gradle.api.tasks.SourceSet
open class TransitiveSourceSetsExtension(private val project: Project) {
open class TransitiveSourceSetsExtension(val project: Project) {
var compileClasspath: FileCollection? = null
var runtimeClasspath: FileCollection? = null

View file

@ -6,6 +6,8 @@ plugins {
id("flywheel.subproject")
}
subproject.init(property("flywheel_group") as String, property("flywheel_version") as String)
val api = sourceSets.create("api")
val lib = sourceSets.create("lib")
val backend = sourceSets.create("backend")
@ -18,20 +20,25 @@ transitiveSourceSets {
sourceSet(api) {
rootCompile()
outgoingClasses()
}
sourceSet(lib) {
rootCompile()
compile(api)
outgoing()
}
sourceSet(backend) {
rootCompile()
compile(api, lib)
outgoing()
}
sourceSet(stubs) {
rootCompile()
outgoingClasses()
}
sourceSet(main) {
compile(api, lib, backend, stubs)
outgoing()
}
sourceSet(sourceSets.getByName("test")) {
implementation(api, lib, backend)
@ -39,6 +46,7 @@ transitiveSourceSets {
sourceSet(vanillin) {
rootCompile()
compile(api, lib)
outgoing()
}
}
@ -47,14 +55,6 @@ defaultPackageInfos {
}
jarSets {
// For sharing with other subprojects.
outgoing("commonApiOnly", api)
outgoing("commonLib", lib)
outgoing("commonBackend", backend)
outgoing("commonStubs", stubs)
outgoing("commonImpl", main)
outgoing("commonVanillin", vanillin)
// For publishing.
create("api", api, lib).apply {
addToAssemble()

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

View file

@ -7,6 +7,8 @@ plugins {
id("flywheel.platform")
}
subproject.init(property("flywheel_group") as String, property("flywheel_version") as String)
val api = sourceSets.create("api")
val lib = sourceSets.create("lib")
val backend = sourceSets.create("backend")
@ -91,9 +93,13 @@ dependencies {
modCompileOnly("maven.modrinth:sodium:${property("sodium_version")}")
"forApi"(project(path = ":common", configuration = "commonApiOnly"))
"forLib"(project(path = ":common", configuration = "commonLib"))
"forBackend"(project(path = ":common", configuration = "commonBackend"))
"forStubs"(project(path = ":common", configuration = "commonStubs"))
"forMain"(project(path = ":common", configuration = "commonImpl"))
"forApi"(project(path = ":common", configuration = "apiClasses"))
"forLib"(project(path = ":common", configuration = "libClasses"))
"forBackend"(project(path = ":common", configuration = "backendClasses"))
"forStubs"(project(path = ":common", configuration = "stubsClasses"))
"forMain"(project(path = ":common", configuration = "mainClasses"))
"forLib"(project(path = ":common", configuration = "libResources"))
"forBackend"(project(path = ":common", configuration = "backendResources"))
"forMain"(project(path = ":common", configuration = "mainResources"))
}

View file

@ -1,9 +1,9 @@
{
"schemaVersion": 1,
"id": "${mod_id}",
"version": "${mod_version}",
"name": "${mod_name}",
"description": "${mod_description}",
"id" : "${flywheel_id}",
"version" : "${flywheel_version}",
"name" : "${flywheel_name}",
"description" : "${flywheel_description}",
"authors": [
"Jozufozu",
"PepperCode1"

View file

@ -7,6 +7,8 @@ plugins {
id("flywheel.platform")
}
subproject.init(property("flywheel_group") as String, property("flywheel_version") as String)
val api = sourceSets.create("api")
val lib = sourceSets.create("lib")
val backend = sourceSets.create("backend")
@ -100,9 +102,13 @@ dependencies {
modCompileOnly("maven.modrinth:embeddium:${property("embeddium_version")}")
"forApi"(project(path = ":common", configuration = "commonApiOnly"))
"forLib"(project(path = ":common", configuration = "commonLib"))
"forBackend"(project(path = ":common", configuration = "commonBackend"))
"forStubs"(project(path = ":common", configuration = "commonStubs"))
"forMain"(project(path = ":common", configuration = "commonImpl"))
"forApi"(project(path = ":common", configuration = "apiClasses"))
"forLib"(project(path = ":common", configuration = "libClasses"))
"forBackend"(project(path = ":common", configuration = "backendClasses"))
"forStubs"(project(path = ":common", configuration = "stubsClasses"))
"forMain"(project(path = ":common", configuration = "mainClasses"))
"forLib"(project(path = ":common", configuration = "libResources"))
"forBackend"(project(path = ":common", configuration = "backendResources"))
"forMain"(project(path = ":common", configuration = "mainResources"))
}

View file

@ -5,34 +5,34 @@ license = "${mod_license}"
issueTrackerURL = "${mod_issues}"
[[mods]]
modId = "${mod_id}"
version = "${mod_version}"
displayName = "${mod_name}"
description = "${mod_description}"
modId = "${flywheel_id}"
version = "${flywheel_version}"
displayName = "${flywheel_name}"
description = "${flywheel_description}"
logoFile = "logo.png"
authors = "Jozufozu, PepperCode1"
displayURL = "${mod_homepage}"
displayTest = "IGNORE_ALL_VERSION"
[[dependencies.${mod_id}]]
[[dependencies.${ flywheel_id }]]
modId = "minecraft"
mandatory = true
versionRange = "${minecraft_maven_version_range}"
side = "CLIENT"
[[dependencies.${mod_id}]]
[[dependencies.${ flywheel_id }]]
modId = "forge"
mandatory = true
versionRange = "${forge_version_range}"
side = "CLIENT"
[[dependencies.${mod_id}]]
[[dependencies.${ flywheel_id }]]
modId = "embeddium"
mandatory = false
versionRange = "[0.3.25,)"
side = "CLIENT"
[[dependencies.${mod_id}]]
[[dependencies.${ flywheel_id }]]
modId = "sodium"
mandatory = false
versionRange = "[0.6.0-beta.2,)"

View file

@ -1,6 +1,6 @@
{
"pack": {
"description": "${mod_name} resources",
"description": "${flywheel_name} resources",
"pack_format": 15
}
}

View file

@ -1,19 +1,21 @@
org.gradle.jvmargs = -Xmx3G
org.gradle.daemon = false
# Mod metadata
mod_id = flywheel
mod_name = Flywheel
mod_version = 1.0.0-beta
mod_description = An overhauled entity and block entity rendering API.
# Common metadata
mod_license = MIT
mod_sources = https://github.com/Engine-Room/Flywheel
mod_issues = https://github.com/Engine-Room/Flywheel/issues
mod_homepage = https://github.com/Engine-Room/Flywheel
# Flywheel metadata
flywheel_id=flywheel
flywheel_name=Flywheel
flywheel_version=1.0.0-beta
flywheel_description=An overhauled entity and block entity rendering API.
# Vanillin metadata
vanillin_id=vanillin
vanillin_name=Vanillin
vanillin_version=1.0.0-beta
vanillin_description=Instanced rendering for entities and block entities via Flywheel.
# Vanillin dependencies
flywheel_maven_version_range=[1.0.0-beta,2.0)
flywheel_semver_version_range=>=1.0.0-beta <2.0.0
@ -41,5 +43,6 @@ sodium_version = mc1.20.1-0.5.11
embeddium_version = 0.3.25+mc1.20.1
# Publication info
group = dev.engine_room.flywheel
flywheel_group=dev.engine_room.flywheel
vanillin_group=dev.engine_room.vanillin
artifact_minecraft_version = 1.20.1

View file

@ -10,7 +10,7 @@ plugins {
id("flywheel.platform")
}
group = "dev.engine_room.vanillin"
subproject.init(property("vanillin_group") as String, property("vanillin_version") as String)
val main = sourceSets.getByName("main")
@ -69,7 +69,10 @@ dependencies {
modCompileOnly("maven.modrinth:sodium:${property("sodium_version")}")
compileOnly(project(path = ":common", configuration = "commonVanillin"))
compileOnly(project(path = ":common", configuration = "vanillinClasses"))
compileOnly(project(path = ":common", configuration = "vanillinResources"))
// JiJ flywheel proper
include(project(path = ":fabric", configuration = "flywheelFabric"))
modRuntimeOnly(project(path = ":fabric", configuration = "flywheelFabric"))
}

View file

@ -27,7 +27,7 @@
"minecraft" : "${minecraft_semver_version_range}",
"fabricloader" : ">=0.15.0",
"fabric-api" : "${fabric_api_version_range}",
"${mod_id}" : "${flywheel_semver_version_range}"
"${flywheel_id}" : "${flywheel_semver_version_range}"
},
"breaks" : {
}

View file

@ -10,7 +10,7 @@ plugins {
id("flywheel.platform")
}
group = "dev.engine_room.vanillin"
subproject.init(property("vanillin_group") as String, property("vanillin_version") as String)
val main = sourceSets.getByName("main")
@ -80,7 +80,10 @@ dependencies {
modCompileOnly("maven.modrinth:embeddium:${property("embeddium_version")}")
compileOnly(project(path = ":common", configuration = "commonVanillin"))
compileOnly(project(path = ":common", configuration = "vanillinClasses"))
compileOnly(project(path = ":common", configuration = "vanillinResources"))
// JiJ flywheel proper
include(project(path = ":forge", configuration = "flywheelForge"))
modRuntimeOnly(project(path = ":forge", configuration = "flywheelForge"))
}

View file

@ -27,7 +27,7 @@ versionRange = "${forge_version_range}"
side = "CLIENT"
[[dependencies.${ vanillin_id }]]
modId = "${mod_id}"
modId = "${flywheel_id}"
mandatory = true
versionRange = "${flywheel_maven_version_range}"
side = "CLIENT"

View file

@ -1,6 +1,6 @@
{
"pack": {
"description": "${mod_name} resources",
"description": "${vanillin_name} resources",
"pack_format": 15
}
}