Search code examples
xcodemacoskotlinkotlin-multiplatformkotlin-native

Kotlin multiplatform macosArm64 "Execution failed for task ':commonizeNativeDistribution'"


There is an example Kotlin Multiplatform code. When I use gradle, the task gradle macos:runDebugExecutableMacosArm64 in the Terminal completes successfully and prints "Hello macos-arm64 native!".

When I try to compile the code into IntelliJ IDEA, the error is printed:

Execution failed for task ':commonizeNativeDistribution'.
> Could not resolve all files for configuration ':kotlinKlibCommonizerClasspath'.
   > Cannot resolve external dependency org.jetbrains.kotlin:kotlin-klib-commonizer-embeddable:1.9.10 because no repositories are defined.

IDEA doesn't even want to accept the build script (everything is highlighted in red).

However, if you remove macosArm64() from the targets and add, for example, jvm(), then the IDEA will take the build script.

My question is what is missing from IDEA to process the build script, and why does this code work without IDEA?

Mac OS X 14.1 aarch64
Xcode 15.0.1 Build version 15A507
Gradle 8.4
Kotlin 1.9.10
JVM 17.0.2 (Oracle Corporation 17.0.2+8-86)
IntelliJ IDEA 2023.2.4 (Community Edition) Build #IC-232.10203.10, built on October 24, 2023

Edit #1

Fleet gives the same error when trying to build the project.

fleet error


Solution

  • The plugin "org.jetbrains.kotlin.multiplatform", which I connect to internal modules, dynamically creates a commonizeNativeDistribution task in the root module. It does not appear in the list of tasks using the gradle tasks command.

    This task tries to download a dependency for itself using the settings of the root module. And not the internal one, who was the initiator and who has the repository indicated, from where he took the plugin. And, apparently, he does it lazily. IDEA knows this and makes sure to run this task as part of the build of all project build scripts. Any way of specifying the mavenCentral() repository in the root module (NOT in the buildScript block) solves this problem.