Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I use the incubating Vector API from Kotlin in a Gradle build?

I want to use the new Vector API from a Kotlin project using a Gradle build.

I tried this:

tasks.withType<KotlinCompile> {
    kotlinOptions.jvmTarget = "17"
    kotlinOptions.freeCompilerArgs = listOf("--add-modules", "jdk.incubator.vector")
}

Result is:

Invalid argument: --add-modules

I've checked and the right SDK is being used, and help for javac at least shows --add-modules as a valid flag, so what I guess is going on is, this is the Kotlin compiler, and I need to provide a different flag, or some kind of prefixed flag to add a module to the classpath. What is the magic incantation here?

like image 533
Hakanai Avatar asked Nov 16 '25 21:11

Hakanai


1 Answers

The Kotlin compiler's argument for this is named -Xadd-modules. You can pass it in this way:

kotlinOptions.freeCompilerArgs = listOf("-Xadd-modules=jdk.incubator.vector")

(Note that right now there is a bug KT-54288 which incorrectly makes this compiler argument unnecessary. So until it's fixed, you can get away without adding it to the build.)

like image 80
Alexander Udalov Avatar answered Nov 18 '25 11:11

Alexander Udalov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!