Skip to content

Commit

Permalink
Split java/resources into different configurations
Browse files Browse the repository at this point in the history
This also avoids the need to package the configurations into
JARs, which saves a bit of time during builds.
  • Loading branch information
jellysquid3 committed Oct 26, 2024
1 parent 5c54d2a commit ee590a1
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 32 deletions.
7 changes: 3 additions & 4 deletions buildSrc/src/main/kotlin/multiloader-platform.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ plugins {
id("maven-publish")
}

val configurationDesktopIntegration: Configuration = configurations.create("commonDesktopIntegration") {
val configurationDesktopIntegrationJava: Configuration = configurations.create("commonDesktopIntegration") {
isCanBeResolved = true
}

dependencies {
configurationDesktopIntegration(project(path = ":common", configuration = "commonDesktop"))
configurationDesktopIntegrationJava(project(path = ":common", configuration = "commonDesktopJava"))
}

tasks {
Expand All @@ -25,8 +25,7 @@ tasks {
from(rootDir.resolve("LICENSE.md"))

// Entry-point for desktop integration when the file is executed directly
dependsOn(configurationDesktopIntegration)
from(configurationDesktopIntegration.map { zipTree(it) })
from(configurationDesktopIntegrationJava)
manifest.attributes["Main-Class"] = "net.caffeinemc.mods.sodium.desktop.LaunchWarn"
}
}
Expand Down
31 changes: 24 additions & 7 deletions common/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -72,21 +72,38 @@ loom {
}
}

// Exports the compiled output of the source set to the named configuration.
fun exportSourceSet(name: String, sourceSet: SourceSet) {
configurations.create(name) {
fun exportSourceSetJava(name: String, sourceSet: SourceSet) {
val configuration = configurations.create("${name}Java") {
isCanBeResolved = true
isCanBeConsumed = true
}

val jarTask = tasks.create<Jar>("${name}Jar") {
destinationDirectory.set(layout.buildDirectory.dir("devlibs/${name}"))
val compileTask = tasks.getByName<JavaCompile>(sourceSet.compileJavaTaskName)
artifacts.add(configuration.name, compileTask.destinationDirectory) {
builtBy(compileTask)
}
}

from(sourceSet.output)
fun exportSourceSetResources(name: String, sourceSet: SourceSet) {
val configuration = configurations.create("${name}Resources") {
isCanBeResolved = true
isCanBeConsumed = true
}

val compileTask = tasks.getByName<ProcessResources>(sourceSet.processResourcesTaskName)
compileTask.apply {
exclude("/*.accesswidener")
}

artifacts.add(name, jarTask)
artifacts.add(configuration.name, compileTask.destinationDir) {
builtBy(compileTask)
}
}

// Exports the compiled output of the source set to the named configuration.
fun exportSourceSet(name: String, sourceSet: SourceSet) {
exportSourceSetJava(name, sourceSet)
exportSourceSetResources(name, sourceSet)
}

exportSourceSet("commonMain", sourceSets["main"])
Expand Down
26 changes: 18 additions & 8 deletions fabric/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,27 @@ base {
archivesName = "sodium-fabric"
}

val configurationCommon: Configuration = configurations.create("common") {
val configurationCommonModJava: Configuration = configurations.create("commonJava") {
isCanBeResolved = true
}
val configurationCommonModResources: Configuration = configurations.create("commonResources") {
isCanBeResolved = true
}

dependencies {
configurationCommon(project(path = ":common", configuration = "commonMain"))
configurationCommon(project(path = ":common", configuration = "commonApi"))
configurationCommon(project(path = ":common", configuration = "commonEarlyLaunch"))
configurationCommonModJava(project(path = ":common", configuration = "commonMainJava"))
configurationCommonModJava(project(path = ":common", configuration = "commonApiJava"))
configurationCommonModJava(project(path = ":common", configuration = "commonEarlyLaunchJava"))

configurationCommonModResources(project(path = ":common", configuration = "commonMainResources"))
configurationCommonModResources(project(path = ":common", configuration = "commonApiResources"))
configurationCommonModResources(project(path = ":common", configuration = "commonEarlyLaunchResources"))
}

sourceSets.apply {
main {
compileClasspath += configurationCommon
runtimeClasspath += configurationCommon
compileClasspath += configurationCommonModJava
runtimeClasspath += configurationCommonModJava
}
}

Expand Down Expand Up @@ -72,7 +79,10 @@ loom {

tasks {
jar {
dependsOn(configurationCommon)
from(configurationCommon.map { zipTree(it) })
from(configurationCommonModJava)
}

processResources {
from(configurationCommonModResources)
}
}
38 changes: 25 additions & 13 deletions neoforge/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,28 @@ sourceSets {
create("service")
}

val configurationCommonMod: Configuration = configurations.create("commonMod") {
val configurationCommonModJava: Configuration = configurations.create("commonModJava") {
isCanBeResolved = true
}
val configurationCommonModResources: Configuration = configurations.create("commonModResources") {
isCanBeResolved = true
}

val configurationCommonEarly: Configuration = configurations.create("commonEarly") {
val configurationCommonServiceJava: Configuration = configurations.create("commonServiceJava") {
isCanBeResolved = true
}
val configurationCommonServiceResources: Configuration = configurations.create("commonServiceResources") {
isCanBeResolved = true
}

dependencies {
configurationCommonMod(project(path = ":common", configuration = "commonMain"))
configurationCommonMod(project(path = ":common", configuration = "commonApi"))
configurationCommonModJava(project(path = ":common", configuration = "commonMainJava"))
configurationCommonModJava(project(path = ":common", configuration = "commonApiJava"))
configurationCommonServiceJava(project(path = ":common", configuration = "commonEarlyLaunchJava"))

configurationCommonEarly(project(path = ":common", configuration = "commonEarlyLaunch"))
configurationCommonModResources(project(path = ":common", configuration = "commonMainResources"))
configurationCommonModResources(project(path = ":common", configuration = "commonApiResources"))
configurationCommonServiceResources(project(path = ":common", configuration = "commonEarlyLaunchResources"))

fun addEmbeddedFabricModule(dependency: String) {
dependencies.implementation(dependency)
Expand All @@ -53,8 +62,8 @@ dependencies {
}

val serviceJar = tasks.create<Jar>("serviceJar") {
dependsOn(configurationCommonEarly)
from(configurationCommonEarly.map { zipTree(it) })
from(configurationCommonServiceJava)
from(configurationCommonServiceResources)

from(sourceSets["service"].output)

Expand All @@ -79,13 +88,13 @@ sourceSets {
compileClasspath = sourceSets["main"].compileClasspath
runtimeClasspath = sourceSets["main"].runtimeClasspath

compileClasspath += configurationCommonEarly
runtimeClasspath += configurationCommonEarly
compileClasspath += configurationCommonServiceJava
runtimeClasspath += configurationCommonServiceJava
}

main {
compileClasspath += configurationCommonMod
runtimeClasspath += configurationCommonMod
compileClasspath += configurationCommonModJava
runtimeClasspath += configurationCommonModJava
}
}

Expand Down Expand Up @@ -122,7 +131,10 @@ neoForge {

tasks {
jar {
dependsOn(configurationCommonMod)
from(configurationCommonMod.map { zipTree(it) })
from(configurationCommonModJava)
}

processResources {
from(configurationCommonModResources)
}
}

0 comments on commit ee590a1

Please sign in to comment.