Skip to content

Commit

Permalink
Buildscript rewrite P1
Browse files Browse the repository at this point in the history
  • Loading branch information
IMS212 committed Oct 4, 2024
1 parent 69a1a28 commit 2255d8e
Show file tree
Hide file tree
Showing 7 changed files with 164 additions and 192 deletions.
23 changes: 12 additions & 11 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@

plugins {
id("java")
id("fabric-loom") version("1.7.2") apply(false)
id("fabric-loom") version("1.7.3") apply(false)
}

val MINECRAFT_VERSION by extra { "1.21.1" }
val NEOFORGE_VERSION by extra { "21.1.62" }
val FABRIC_LOADER_VERSION by extra { "0.16.0" }
val FABRIC_API_VERSION by extra { "0.102.0+1.21.1" }
val SODIUM_FILE by extra { "sodium-LOADER-0.6.0-beta.2+mc1.21.1.jar" }
val NEOFORGE_VERSION by extra { "21.1.46" }
val FABRIC_LOADER_VERSION by extra { "0.16.4" }
val FABRIC_API_VERSION by extra { "0.103.0+1.21.1" }

// This value can be set to null to disable Parchment.
// TODO: Re-add Parchment
val PARCHMENT_VERSION by extra { null }

// https://semver.org/
val MOD_VERSION by extra { "1.8.0-beta.5" }
Expand All @@ -22,17 +25,15 @@ tasks.withType<JavaCompile> {
options.encoding = "UTF-8"
}

tasks.jar {
enabled = false
}

subprojects {
apply(plugin = "maven-publish")

java.toolchain.languageVersion = JavaLanguageVersion.of(21)

repositories {
maven {
name = "ParchmentMC"
url = uri("https://maven.parchmentmc.org")
}
}

fun createVersionString(): String {
val builder = StringBuilder()
Expand Down
77 changes: 43 additions & 34 deletions common/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,17 +1,30 @@
import net.fabricmc.loom.task.AbstractRemapJarTask

plugins {
id("java")
id("idea")
id("fabric-loom") version "1.7.2"
id("fabric-loom") version "1.7.3"
id("com.github.gmazzo.buildconfig") version "5.3.5"
}

repositories {
maven("https://maven.parchmentmc.org/")

exclusiveContent {
forRepository {
maven {
name = "Modrinth"
url = uri("https://api.modrinth.com/maven")
}
}
filter {
includeGroup("maven.modrinth")
}
}
}

val MINECRAFT_VERSION: String by rootProject.extra
val PARCHMENT_VERSION: String? by rootProject.extra
val FABRIC_LOADER_VERSION: String by rootProject.extra
val FABRIC_API_VERSION: String by rootProject.extra
val SODIUM_VERSION: String by rootProject.extra
val SODIUM_FILE: String by rootProject.extra

sourceSets.create("desktop")

Expand All @@ -31,61 +44,49 @@ buildConfig {
}
}

// This trick hides common tasks in the IDEA list.
tasks.configureEach {
group = null
}

dependencies {
minecraft(group = "com.mojang", name = "minecraft", version = MINECRAFT_VERSION)
mappings(loom.layered {

mappings(loom.layered() {
officialMojangMappings()
parchment("org.parchmentmc.data:parchment-1.21:2024.07.28@zip")
if (PARCHMENT_VERSION != null) {
parchment("org.parchmentmc.data:parchment-${MINECRAFT_VERSION}:${PARCHMENT_VERSION}@zip")
}
})
modCompileOnly("net.fabricmc:fabric-loader:$FABRIC_LOADER_VERSION")

modImplementation("net.fabricmc:fabric-loader:$FABRIC_LOADER_VERSION")

modCompileOnly("net.fabricmc.fabric-api:fabric-renderer-api-v1:3.2.9+1172e897d7")

modImplementation("maven.modrinth", "sodium", "mc1.21-0.6.0-beta.2-fabric")
modCompileOnly("org.antlr:antlr4-runtime:4.13.1")
modCompileOnly("io.github.douira:glsl-transformer:2.0.1")
modCompileOnly("org.anarres:jcpp:1.4.14")

modCompileOnly(files(rootDir.resolve("custom_sodium").resolve(SODIUM_FILE.replace("LOADER", "fabric"))))

modCompileOnly(files(rootDir.resolve("DHApi.jar")))
}

tasks.withType<AbstractRemapJarTask>().forEach {
it.targetNamespace = "named"
compileOnly(files(rootDir.resolve("DHApi.jar")))
}

sourceSets {
val main = getByName("main")
val test = getByName("test")
val headers = create("headers")
val vendored = create("vendored")
val sodiumCompatibility = create("sodiumCompatibility")
val desktop = getByName("desktop")

headers.apply {
java {
compileClasspath += main.compileClasspath
}
}

test.apply {
java {
compileClasspath += main.compileClasspath
compileClasspath += main.output
}
}

vendored.apply {
java {
compileClasspath += main.compileClasspath
}
}

sodiumCompatibility.apply {
desktop.apply {
java {
compileClasspath += main.compileClasspath
compileClasspath += main.output
srcDir("src/desktop/java")
}
}

Expand All @@ -109,7 +110,6 @@ loom {
mods {
val main by creating { // to match the default mod generated for Forge
sourceSet("vendored")
sourceSet("sodiumCompatibility")
sourceSet("main")
}
}
Expand All @@ -128,6 +128,15 @@ tasks {
from(vendored.output.classesDirs)
from(vendored.output.resourcesDir)

manifest.attributes["Main-Class"] = "net.caffeinemc.mods.sodium.desktop.LaunchWarn"
val desktop = sourceSets.getByName("desktop")
from(desktop.output.classesDirs)
from(desktop.output.resourcesDir)

manifest.attributes["Main-Class"] = "net.irisshaders.iris.LaunchWarn"
}
}

// This trick hides common tasks in the IDEA list.
tasks.configureEach {
group = null
}
130 changes: 52 additions & 78 deletions fabric/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,125 +1,108 @@
plugins {
java
idea
`maven-publish`
id("fabric-loom") version("1.7.2")
id("java")
id("idea")
id("fabric-loom") version ("1.7.3")
}

val MINECRAFT_VERSION: String by rootProject.extra
val PARCHMENT_VERSION: String? by rootProject.extra
val FABRIC_LOADER_VERSION: String by rootProject.extra
val FABRIC_API_VERSION: String by rootProject.extra
val MOD_VERSION: String by rootProject.extra
val SODIUM_FILE: String by rootProject.extra

repositories {
exclusiveContent {
forRepository {
maven {
name = "Modrinth"
url = uri("https://api.modrinth.com/maven")
}
}
filter {
includeGroup("maven.modrinth")
}
}
}

base {
archivesName.set("iris-fabric")
}

sourceSets {
main.get().apply {
compileClasspath += project(":common").sourceSets.getByName("headers").output
}
}

dependencies {
minecraft("com.mojang:minecraft:${MINECRAFT_VERSION}")
mappings(loom.layered {
officialMojangMappings()
parchment("org.parchmentmc.data:parchment-1.21:2024.07.28@zip")
if (PARCHMENT_VERSION != null) {
parchment("org.parchmentmc.data:parchment-${MINECRAFT_VERSION}:${PARCHMENT_VERSION}@zip")
}
})
modImplementation("net.fabricmc:fabric-loader:$FABRIC_LOADER_VERSION")

fun addRuntimeFabricModule(name: String) {
val module = fabricApi.module(name, FABRIC_API_VERSION)
modRuntimeOnly(module)
}

fun addEmbeddedFabricModule(name: String) {
val module = fabricApi.module(name, FABRIC_API_VERSION)
modImplementation(module)
include(module)
}

fun addRuntimeFabricModule(name: String) {
val module = fabricApi.module(name, FABRIC_API_VERSION)
modRuntimeOnly(module)
fun implementAndInclude(name: String) {
modImplementation(name)
include(name)
}

// Fabric API modules
addEmbeddedFabricModule("fabric-api-base")
addEmbeddedFabricModule("fabric-key-binding-api-v1")

modImplementation("org.antlr:antlr4-runtime:4.13.1")
include("org.antlr:antlr4-runtime:4.13.1")
modImplementation("io.github.douira:glsl-transformer:2.0.1")
include("io.github.douira:glsl-transformer:2.0.1")
modImplementation("org.anarres:jcpp:1.4.14")
include("org.anarres:jcpp:1.4.14")

modImplementation(files(rootDir.resolve("custom_sodium").resolve(SODIUM_FILE.replace("LOADER", "fabric"))))

modCompileOnly(files(rootDir.resolve("DHApi.jar")))

modRuntimeOnly(group = "com.lodborg", name = "interval-tree", version = "1.0.0")

addRuntimeFabricModule("fabric-api-base")
addRuntimeFabricModule("fabric-block-view-api-v2")
addRuntimeFabricModule("fabric-renderer-api-v1")
addRuntimeFabricModule("fabric-rendering-data-attachment-v1")
addRuntimeFabricModule("fabric-rendering-fluids-v1")
addRuntimeFabricModule("fabric-resource-loader-v0")

implementation("com.google.code.findbugs:jsr305:3.0.1")
compileOnly(project(":common"))
modImplementation("maven.modrinth", "sodium", "mc1.21-0.6.0-beta.2-fabric")
implementAndInclude("org.antlr:antlr4-runtime:4.13.1")
implementAndInclude("io.github.douira:glsl-transformer:2.0.1")
implementAndInclude("org.anarres:jcpp:1.4.14")

implementation(project.project(":common").sourceSets.getByName("vendored").output)
compileOnly(project.project(":common").sourceSets.getByName("headers").output)
implementation(project.project(":common").sourceSets.getByName("main").output)

compileOnly(files(rootDir.resolve("DHApi.jar")))
}

tasks.named("compileTestJava").configure {
enabled = false
}

tasks.named("test").configure {
enabled = false
}

loom {
if (project(":common").file("src/main/resources/iris.accesswidener").exists())
accessWidenerPath.set(project(":common").file("src/main/resources/iris.accesswidener"))

@Suppress("UnstableApiUsage")
mixin { defaultRefmapName.set("iris.refmap.json") }
mixin { defaultRefmapName.set("iris-fabric.refmap.json") }

runs {
named("client") {
client()
configName = "Fabric Client"
ideConfigGenerated(true)
vmArgs("-Dmixin.debug.export=true")
runDir("run")
}
create("clientQuickplay") {
client()
configName = "Fabric Client"
ideConfigGenerated(true)
programArgs("--quickPlaySingleplayer", "\"GAMING\"")
runDir("run")
}
named("server") {
server()
configName = "Fabric Server"
ideConfigGenerated(true)
runDir("run")
}
}
}

tasks {
getByName("compileTestJava") {
enabled = false
}

getByName("test") {
enabled = false
}

withType<JavaCompile> {
source(project(":common").sourceSets.main.get().allSource)
source(project(":common").sourceSets.getByName("desktop").allSource)
source(project(":common").sourceSets.getByName("vendored").allSource)
}

javadoc { source(project(":common").sourceSets.main.get().allJava) }

processResources {
from(project(":common").sourceSets.main.get().resources)

from(project.project(":common").sourceSets.main.get().resources)
inputs.property("version", project.version)

filesMatching("fabric.mod.json") {
Expand All @@ -128,21 +111,12 @@ tasks {
}

jar {
from(rootDir.resolve("LICENSE.md"))
duplicatesStrategy = DuplicatesStrategy.EXCLUDE

manifest.attributes["Main-Class"] = "net.irisshaders.iris.LaunchWarn"
}
}
from(zipTree(project.project(":common").tasks.jar.get().archiveFile))

publishing {
publications {
register("mavenJava", MavenPublication::class) {
artifactId = base.archivesName.get()
from(components["java"])
}
manifest.attributes["Main-Class"] = "net.irisshaders.iris.LaunchWarn"
}

repositories {
maven("file://${System.getenv("local_maven")}")
}
remapJar.get().destinationDirectory = rootDir.resolve("build").resolve("libs")
}
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
org.gradle.jvmargs = -Xmx4G
org.gradle.caching=true
org.gradle.parallel=true
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.1-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Loading

0 comments on commit 2255d8e

Please sign in to comment.