Skip to content

Commit

Permalink
Should have worn steel toe boots
Browse files Browse the repository at this point in the history
- Add "stub" sourceset to each subproject
- Directly pass vararg sourcesets to methods in PlatformExtension to
  avoid automatically shipping jars with the api stubs
- We may have to include stubs in setupLoomMod, but I don't think so
- A lot of this can be stripped back out if we don't need stub sources
  for the forge/fabric subprojects
  • Loading branch information
Jozufozu committed Oct 17, 2024
1 parent 59292e9 commit 3180999
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,11 @@ open class PlatformExtension(val project: Project) {

var apiArtifactId: String = "flywheel-${project.name}-api-${project.property("artifact_minecraft_version")}"

private val sources = mutableSetOf<SourceSet>()
private val commonSourceSets: SourceSetContainer by lazy { commonProject.the<SourceSetContainer>() }

fun sources(vararg sourceSets: SourceSet) {
this.sources.addAll(sourceSets)
}

fun setupLoomMod() {
fun setupLoomMod(vararg sourceSets: SourceSet) {
project.the<LoomGradleExtensionAPI>().mods.maybeCreate("main").apply {
sources.forEach(::sourceSet)
sourceSets.forEach(::sourceSet)
}
}

Expand Down Expand Up @@ -61,13 +56,13 @@ open class PlatformExtension(val project: Project) {
}
}

fun compileWithCommonSourceSets() {
fun compileWithCommonSourceSets(vararg sourceSets: SourceSet) {
project.tasks.apply {
withType<JavaCompile>().configureEach {
JarTaskSet.excludeDuplicatePackageInfos(this)
}

sources.forEach {
sourceSets.forEach {
val commonSourceSet = commonSourceSets.named(it.name).get()

named<JavaCompile>(it.compileJavaTaskName).configure {
Expand All @@ -80,10 +75,10 @@ open class PlatformExtension(val project: Project) {
}
}

fun setupFatJar() {
fun setupFatJar(vararg sourceSets: SourceSet) {
project.tasks.apply {
val extraSourceSets = sources.filter { it.name != "main" }.toList()
val commonSources = sources.map { commonSourceSets.named(it.name).get() }
val extraSourceSets = sourceSets.filter { it.name != "main" }.toList()
val commonSources = sourceSets.map { commonSourceSets.named(it.name).get() }

named<Jar>("jar").configure {
extraSourceSets.forEach { from(it.output) }
Expand Down
7 changes: 6 additions & 1 deletion common/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ plugins {
val api = sourceSets.create("api")
val lib = sourceSets.create("lib")
val backend = sourceSets.create("backend")
val stubs = sourceSets.create("stubs")
val main = sourceSets.getByName("main")

transitiveSourceSets {
Expand All @@ -25,8 +26,11 @@ transitiveSourceSets {
rootCompile()
compile(api, lib)
}
sourceSet(stubs) {
rootCompile()
}
sourceSet(main) {
compile(api, lib, backend)
compile(api, lib, backend, stubs)
}
sourceSet(sourceSets.getByName("test")) {
implementation(api, lib, backend)
Expand All @@ -42,6 +46,7 @@ jarSets {
outgoing("commonApiOnly", api)
outgoing("commonLib", lib)
outgoing("commonBackend", backend)
outgoing("commonStubs", stubs)
outgoing("commonImpl", main)

// For publishing.
Expand Down
14 changes: 10 additions & 4 deletions fabric/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ plugins {
val api = sourceSets.create("api")
val lib = sourceSets.create("lib")
val backend = sourceSets.create("backend")
val stubs = sourceSets.create("stubs")
val main = sourceSets.getByName("main")

transitiveSourceSets {
Expand All @@ -26,7 +27,12 @@ transitiveSourceSets {
rootCompile()
compile(api, lib)
}
sourceSet(stubs) {
rootCompile()
}
sourceSet(main) {
// Don't want stubs at runtime
compile(stubs)
implementation(api, lib, backend)
}

Expand All @@ -35,11 +41,10 @@ transitiveSourceSets {

platform {
commonProject = project(":common")
sources(api, lib, backend, main)
compileWithCommonSourceSets()
setupLoomMod()
compileWithCommonSourceSets(api, lib, backend, stubs, main)
setupLoomMod(api, lib, backend, main)
setupLoomRuns()
setupFatJar()
setupFatJar(api, lib, backend, main)
}

jarSets {
Expand Down Expand Up @@ -80,5 +85,6 @@ dependencies {
"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"))
}
14 changes: 9 additions & 5 deletions forge/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ plugins {
val api = sourceSets.create("api")
val lib = sourceSets.create("lib")
val backend = sourceSets.create("backend")
val stubs = sourceSets.create("stubs")
val main = sourceSets.getByName("main")

transitiveSourceSets {
Expand All @@ -26,20 +27,22 @@ transitiveSourceSets {
rootCompile()
compile(api, lib)
}
sourceSet(stubs) {
rootCompile()
}
sourceSet(main) {
compile(api, lib, backend)
compile(api, lib, backend, stubs)
}

createCompileConfigurations()
}

platform {
commonProject = project(":common")
sources(api, lib, backend, main)
compileWithCommonSourceSets()
setupLoomMod()
compileWithCommonSourceSets(api, lib, backend, stubs, main)
setupLoomMod(api, lib, backend, main)
setupLoomRuns()
setupFatJar()
setupFatJar(api, lib, backend, main)
}

jarSets {
Expand Down Expand Up @@ -91,5 +94,6 @@ dependencies {
"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"))
}

0 comments on commit 3180999

Please sign in to comment.