Kotlin compiler can't find FabricBlockSettings class from fabric-object-builder-api-v1
ignirtoq opened this issue ยท 3 comments
Summary
When adding the line
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings
to a fresh clone the example Fabric Kotlin mod (here), the following errors are seen:
e: C:\[...]\MinimalImportError\src\main\kotlin\net\fabricmc\example\ExampleMod.kt: (3, 32): Qualified name must be a '.'-separated identifier list
e: C:\[...]\MinimalImportError\src\main\kotlin\net\fabricmc\example\ExampleMod.kt: (3, 39): Unresolved reference: builder
Steps to Reproduce
- Download a fresh clone of the Kotlin example mod: https://github.com/natanfudge/fabric-example-mod-kotlin
- Update the gradle.properties file with the latest Fabric versions provided from here: https://modmuss50.me/fabric.html. My case is copied below:
kotlin.code.style=official
org.gradle.jvmargs=-Xmx1G
# Fabric Properties
# Check these on https://modmuss50.me/fabric.html
minecraft_version=1.16.4
yarn_mappings=1.16.4+build.7
loader_version=0.10.8
#Fabric api
fabric_version=0.28.1+1.16
loom_version=0.5-SNAPSHOT
# Mod Properties
mod_version = 1.0.0
maven_group = net.minimalproblem
archives_base_name = minimal-import-error-mod
# Kotlin
kotlin_version=1.4.0
fabric_kotlin_version=1.4.0+build.1
- Prepare the development environment as outlined here: https://fabricmc.net/wiki/tutorial:setup. In my case I started with VS Code, then blew away the entire project folder and tried again with IntelliJ, yielding the same results.
- Update the
src/main/kotlin/net/fabricmc/example/ExampleMod.kt
file and add the following as line 3:
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings
- Run either the
runClient
orcompileKotlin
Gradle task (the compile task is a dependency of the run task, so either will fail in the same place).
Environment
- Java 8 Update 221 (for Minecraft)
- AdoptOpenJDK 11.0.9.11 (for VS Code Java extensions)
This isn't really a bug. object
is a keyword in Kotlin, so it needs to be escaped with backticks:
import net.fabricmc.fabric.api.`object`.builder.v1.block.FabricBlockSettings
IDEA should do this automatically for you as well.