Centrifuge

- Separate common project into 4 source sets
- Declare outgoing configurations for forge/fabric to depend on
- Re-compile source from each source set in each platform's compileJava
This commit is contained in:
Jozufozu 2024-04-24 14:06:20 -07:00
parent cdaf6d2394
commit 82a098626b
384 changed files with 82 additions and 11 deletions

View File

@ -25,17 +25,37 @@ loom {
}
}
dependencies {
compileOnly project(path: ':common', configuration: 'commonApi')
compileOnly project(path: ':common', configuration: 'commonLib')
compileOnly project(path: ':common', configuration: 'commonBackend')
compileOnly project(path: ':common', configuration: 'commonImpl')
}
SourceSet commonApiSource = project(':common').sourceSets.api
SourceSet commonLibSource = project(':common').sourceSets.lib
SourceSet commonBackendSource = project(':common').sourceSets.backend
SourceSet commonMainSource = project(':common').sourceSets.main
def commonSources = [commonApiSource, commonLibSource, commonBackendSource, commonMainSource]
tasks.named('processResources', ProcessResources).configure { ProcessResources processResources ->
processResources.from project(':common').tasks.named('processResources', ProcessResources).get().source
// No resources in API
processResources.from commonLibSource.resources
processResources.from commonBackendSource.resources
processResources.from commonMainSource.resources
}
tasks.named('compileJava', JavaCompile).configure { JavaCompile compileJava ->
compileJava.source project(':common').tasks.named('compileJava', JavaCompile).get().source
// TODO: Can we avoid this duplication? Would be nice to repackage the 4 common jars without having to re compile
commonSources.forEach { compileJava.source it.allJava }
excludeDuplicatePackageInfos(compileJava)
}
tasks.named('javadoc', Javadoc).configure { Javadoc javadoc ->
javadoc.source project(':common').tasks.named('javadoc', Javadoc).get().source
commonSources.forEach { javadoc.source it.allJava }
excludeDuplicatePackageInfos(javadoc)
}
@ -44,9 +64,7 @@ tasks.named('jar', Jar).configure { Jar jar ->
}
tasks.named('sourcesJar', Jar).configure { Jar jar ->
def commonSources = project(':common').tasks.named('sourcesJar', Jar)
dependsOn commonSources
jar.from zipTree(commonSources.flatMap { it.archiveFile })
commonSources.forEach { jar.from it.allJava }
excludeDuplicatePackageInfos(jar)
}

View File

@ -7,7 +7,64 @@ plugins {
apply from: rootProject.file('buildSrc/simple-java.gradle')
apply from: rootProject.file('buildSrc/subprojects.gradle')
apply from: rootProject.file('buildSrc/package-infos.gradle')
// TODO: package-infos specifically targets the main source set
// apply from: rootProject.file('buildSrc/package-infos.gradle')
sourceSets {
// Loom only populates mc stuff to the main source set,
// so grab that here and use it for the others.
// Note that the `+` operator does NOT perform a deep copy
// of a FileCollection, so this object is shared between
// the source sets and we should avoid mutating it.
FileCollection mcCompileClassPath = main.compileClasspath
SourceSet api = api {
compileClasspath = mcCompileClassPath
}
SourceSet lib = lib {
compileClasspath = mcCompileClassPath + api.output
}
SourceSet backend = backend {
compileClasspath = mcCompileClassPath + api.output + lib.output
}
main {
// Assign here rather than concatenate to avoid modifying the mcCompileClassPath FileCollection
compileClasspath = mcCompileClassPath + api.output + lib.output + backend.output
}
test {
// Only test needs runtimeClasspath filled since the game shouldn't run from common alone.
// Fine to concatenate here.
compileClasspath += api.output + lib.output + backend.output
runtimeClasspath += api.output + lib.output + backend.output
}
}
TaskProvider<Jar> createJarAndOutgoingConfiguration(String name) {
return createJarAndOutgoingConfiguration(name, sourceSets.named(name).get())
}
TaskProvider<Jar> createJarAndOutgoingConfiguration(String name, SourceSet sourceSet) {
def config = configurations.register("common${name.capitalize()}") {
canBeConsumed = true
canBeResolved = false
}
def jarTask = tasks.register("${name}Jar", Jar) {
archiveClassifier.set(name)
from sourceSet.output
}
artifacts.add(config.name, jarTask)
return jarTask
}
// TODO: repackage these for maven publication
def apiJar = createJarAndOutgoingConfiguration("api")
def libJar = createJarAndOutgoingConfiguration("lib")
def backendJar = createJarAndOutgoingConfiguration("backend")
def implJar = createJarAndOutgoingConfiguration("impl", sourceSets.main)
dependencies {
modCompileOnly "net.fabricmc:fabric-loader:${fabric_loader_version}"

Some files were not shown because too many files have changed in this diff Show More