https://kotlinlang.org logo
#gradle
Title
# gradle
a

Andrew

09/25/2023, 2:48 PM
Hi, I'm very stuck with an inability to compile Kotlin Native as part of a gradle build process. This also appears to affect Kotlin JVM targets too. The issue is that when running any kind of build, gradle compiles intermediate files only, but not .jar or binary executables. I have tried removing and wiping Java and Kotlin from system and user configs, caches, etc to start with a clean slate, but none of that seems to help. I also tested a new user account on the malfunctioning system, but it ran into the same problems, which points to an issue outside my home directory. I'm using Ubuntu, which was installed as a server, then upgraded to a desktop install. I tried building the same exact code on an Ubuntu desktop virtual machine, and it works. Not sure what's different. I have gradle installed via sdkman, and don't have Kotlin installed, but it seems to get pulled in via the build step, at least for the Ubuntu vm. Any help is appreciated. Thank you. : ) From `gradle build -i`:
Copy code
...
> Task :compileKotlinNative NO-SOURCE
Skipping task ':compileKotlinNative' as it has no source files and no previous output files.
Resolve mutations for :linkDebugExecutableNative (Thread[#345,Execution worker,5,main]) started.
:linkDebugExecutableNative (Thread[#356,Execution worker Thread 11,5,main]) started.
...
Re-installing Ubuntu and using a fresh user account did not resolve the issue. Here's the source code I'm running into problems with:
Copy code
// build.gradle.kts
plugins {
    kotlin("multiplatform") version "1.9.10"
}

repositories {
    mavenCentral()
}

kotlin {
    linuxX64("native") {
        binaries {
            executable()
        }
    }
}

tasks.withType<Wrapper> {
    gradleVersion = "8.3"
    distributionType = Wrapper.DistributionType.BIN
}
settings.gradle.kts
is empty, and there source code is:
Copy code
// src/kotlinMain/kotlin/hello.kt
fun main() {
    println("Hello, Kotlin/Native!")
}
a

Adam S

09/25/2023, 8:50 PM
The file is in the wrong location:
src/kotlinMain
should be
src/commonMain
a

Andrew

09/25/2023, 9:11 PM
Yes, that's it! Thank you! 🎉 I'll have to read more carefully next time... 😅