Skip to content

Add Kotlin build script#156

Merged
modmuss50 merged 20 commits intoFabricMC:mainfrom
CelDaemon:kotlin-dsl
Mar 7, 2026
Merged

Add Kotlin build script#156
modmuss50 merged 20 commits intoFabricMC:mainfrom
CelDaemon:kotlin-dsl

Conversation

@CelDaemon
Copy link
Contributor

@CelDaemon CelDaemon commented Feb 21, 2026

Unlike the other PR, this one tries to stay as similar as possible to the Groovy build script.

The only big difference is the loom version being set in the settings.gradle.kts file.

@CelDaemon
Copy link
Contributor Author

Is missing config from fabric cli, I would convert to a draft but there seems to be no option to do that from the GitHub mobile app.

Copy link
Member

@modmuss50 modmuss50 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also update the CLI and add it to the test script here: https://github.com/FabricMC/fabricmc.net/blob/main/cli/test.ts and run the tests to make sure this works on all versions.

@CelDaemon
Copy link
Contributor Author

I have successfully ran the tests (158 passed), though with the Kotlin language disabled and an extra check to skip yarn on unobfuscated versions.

image

Changes property access to use Gradle property providers instead of
project property binding. Using Gradle properties in this way avoids
issues when using Isolated Projects
(gradle/gradle#32398).

An alternative is to use `project.property(...)` instead, which is
closer to the Groovy variant but does exhibit these issues.
Shares the gradle.properties.eta file between the Groovy and Kotlin DSL build script types.
@CelDaemon CelDaemon requested a review from modmuss50 February 23, 2026 19:26

// Fabric API. This is technically optional, but you probably want it anyway.
<% if (it.unobfuscated) { %>implementation<% } else { %>modImplementation<% } %>("net.fabricmc.fabric-api:fabric-api:${providers.gradleProperty("fabric_api_version").get()}")
<% if (it.kotlin) { %><% if (it.unobfuscated) { %>implementation<% } else { %>modImplementation<% } %>("net.fabricmc:fabric-language-kotlin:${providers.gradleProperty("fabric_kotlin_version").get()}")<% } %>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

General thought about these dep strings: I wonder if

modImplementation("net.fabricmc:fabric-language-kotlin:" + providers.gradleProperty("fabric_kotlin_version").get())

would be cleaner/easier to read than

modImplementation("net.fabricmc:fabric-language-kotlin:${providers.gradleProperty("fabric_kotlin_version").get()}")

I'm fine with either in any case.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah it might be, it's closer to the groovy version like this though

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kotlin idioms. use string templating not concatenation

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also, if you're going to use providers, you may as well use .map {} instead of immediately resolving it. otherwise just use property("...")

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

property is being avoided to work around some issues relating to Isolated Projects. But yeah, mapping is a good idea.

Comment on lines +62 to +80
tasks.withType<JavaCompile>().configureEach {
options.release = <%= it.java.release %>
}
<% if (it.kotlin) { %>
kotlin {
compilerOptions {
jvmTarget = JvmTarget.JVM_<%= it.java.compatibility %>
}
}
<% } %>
java {
// Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task
// if it is present.
// If you remove this line, sources will not be generated.
withSourcesJar()

sourceCompatibility = JavaVersion.VERSION_<%= it.java.compatibility %>
targetCompatibility = JavaVersion.VERSION_<%= it.java.compatibility %>
}
Copy link

@isXander isXander Feb 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
tasks.withType<JavaCompile>().configureEach {
options.release = <%= it.java.release %>
}
<% if (it.kotlin) { %>
kotlin {
compilerOptions {
jvmTarget = JvmTarget.JVM_<%= it.java.compatibility %>
}
}
<% } %>
java {
// Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task
// if it is present.
// If you remove this line, sources will not be generated.
withSourcesJar()
sourceCompatibility = JavaVersion.VERSION_<%= it.java.compatibility %>
targetCompatibility = JavaVersion.VERSION_<%= it.java.compatibility %>
}
java {
toolchain {
languageVersion = JavaLanguageVersion.of(<%= it.java.compatibility %>)
}
// Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task
// if it is present.
// If you remove this line, sources will not be generated.
withSourcesJar()
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a breaking change as it forces gradle to use a specific JDK version instead of configuring the target of the active toolchain. Should probably be a separate PR if you wish to change this.

@modmuss50
Copy link
Member

Going to merge this, if there are any future suggestions/improvements they can always be done later.

@modmuss50 modmuss50 merged commit 46c25aa into FabricMC:main Mar 7, 2026
2 checks passed
@modmuss50 modmuss50 mentioned this pull request Mar 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants