FabricMC / fabric-loom

Gradle build system plugin used to automate the setup of a minecraft mod development environment.
MIT License
242 stars 212 forks source link

Seems loom is not loading the Scala build correctly #1078

Open Krysztal112233 opened 8 months ago

Krysztal112233 commented 8 months ago

Context

I was trying to fix fabric-language-scala when I didn't manage to run up my code at the last stage, it prompted me that I couldn't find my main entry, which I found strange. As I was adding breakpoints to the entry point I noticed that it seems that fabric is not adding the results of my scala build to the loader? But this seems to be a loom issue?

Off-topic, I want to fix fabric-language-scala because I need to use the high-level mathematical abstractions provided by Scala's powerful type system, so I have to fix it, and I'd even like to help maintain fabric-language-scala if I can.

Also linked to fabric-language-scala's 24/23 The fabric-language-scala fork Krysztal112233/fabric-language-scala

Build Script

Here's my build.gradle.

plugins {
    id 'fabric-loom' version '1.5-SNAPSHOT'
    id 'maven-publish'
    id 'scala'
    id 'java-library'
}

version = project.mod_version
group = project.maven_group

base {
    archivesName = project.archives_base_name
}

repositories {
    // Add repositories to retrieve artifacts from in here.
    // You should only use this when depending on other mods because
    // Loom adds the essential maven repositories to download Minecraft and libraries from automatically.
    // See https://docs.gradle.org/current/userguide/declaring_repositories.html
    // for more information about repositories.
    mavenLocal()
}

loom {
    splitEnvironmentSourceSets()

    mods {
        "kmmo" {
            sourceSet sourceSets.main
            sourceSet sourceSets.client
        }
    }
}

tasks.compileScala.classpath = sourceSets.main.compileClasspath
tasks.compileJava.classpath += files(sourceSets.main.scala.classesDirectory)

dependencies {
    minecraft "com.mojang:minecraft:${project.minecraft_version}"
    mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
    modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"

    modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"

    modImplementation "net.fabricmc:fabric-language-scala:19.1.0+scala.${project.scala_version}.local"
    implementation "org.scala-lang:scala3-library_3:${project.scala_version}"

    // Extra dependencies
    compileOnly 'org.jetbrains:annotations:24.1.0'
}

processResources {
    inputs.property "version", project.version

    filesMatching("fabric.mod.json") {
        expand "version": project.version
    }
}

tasks.withType(JavaCompile).configureEach {
    it.options.release = 17
}

java {
    withSourcesJar()

    sourceCompatibility = JavaVersion.VERSION_17
    targetCompatibility = JavaVersion.VERSION_17
}

jar {
    from("LICENSE") {
        rename { "${it}_${project.base.archivesName.get()}"}
    }
}

// configure the maven publication
publishing {
    publications {
        mavenJava(MavenPublication) {
            from components.java
        }
    }

    // See https://docs.gradle.org/current/userguide/publishing_maven.html for information on how to set up publishing.
    repositories {
        // Add repositories to publish to here.
        // Notice: This block does NOT have the same function as the block in the top level.
        // The repositories here will be used for publishing your artifact, not for
        // retrieving dependencies.
    }
}
lego-eden commented 5 months ago

Hello! I would very much like to help out here, but I am a complete noob when it comes to both modding and loom. Although I would say I am decent at scala, and I would very much like to use it for the same reason as you: the type system. Have you come up with a fix for this?

lego-eden commented 5 months ago

Hello! I would very much like to help out here, but I am a complete noob when it comes to both modding and loom. Although I would say I am decent at scala, and I would very much like to use it for the same reason as you: the type system. Have you come up with a fix for this?

I have managed to run a mod made with scala now. The mod can be found here: https://github.com/lego-eden/fabricmod-scala-template

Krysztal112233 commented 5 months ago

Hello! I would very much like to help out here, but I am a complete noob when it comes to both modding and loom. Although I would say I am decent at scala, and I would very much like to use it for the same reason as you: the type system. Have you come up with a fix for this?

I think it's probably insoluble.

As you can see, I created a fabric-language-scala fork called krysztal-language-scala and rewrote the loading part of the code to make it possible to properly use Scala3 as the language for writing mods.

Many thanks to the main maintainers of fabricmc, they have worked very hard. So I've decided that I'm going to ease their burden by maintaining a krysztal-language-scala myself. So if you have any problems with kls please go to the kls repository and I will try to solve them for you!