Hi, I have JDK provisioning configured with two ac...
# kotlin-toolchain
s
Hi, I have JDK provisioning configured with two acceptable distributions. I expected it to use or download the first matching distribution, but it downloads both
Copy code
settings:
  jvm:
    release: 21
    storeParameterNames: true
    jdk:
      version: 25
      distributions: [ zulu, temurin ]
Copy code
This is the first run of the Kotlin CLI v0.14.0-dev-4523, so we need to download the Kotlin Toolchain.
Please give us a few seconds, subsequent runs will be faster.
Downloading Kotlin Toolchain distribution v0.14.0-dev-4523...
Download complete.
Downloading Kotlin CLI runtime v25.32.21...
Download complete.
Downloading <https://repo1.maven.org/maven2/org/jetbrains/kotlin/kotlin-native-prebuilt/2.5.0-Beta2/kotlin-native-prebuilt-2.5.0-Beta2-macos-aarch64.tar.gz> to /Users/runner/work/kotlin-vipaccess/kotlin-vipaccess/.kotlin/shared-cache/download.cache/b0bc012aaf-kotlin-native-prebuilt-2.5.0-Beta2-macos-aarch64.tar.gz
Downloading <https://github.com/pnpm/pnpm/releases/download/v11.9.0/pnpm-darwin-arm64.tar.gz> to /Users/runner/work/kotlin-vipaccess/kotlin-vipaccess/.kotlin/shared-cache/download.cache/bfff255e35-pnpm-darwin-arm64.tar.gz
Downloading <https://cdn.azul.com/zulu/bin/zulu25.36.205-ca-jdk25.0.4.1-macosx_aarch64.tar.gz> to /Users/runner/work/kotlin-vipaccess/kotlin-vipaccess/.kotlin/shared-cache/download.cache/15bced2243-zulu25.36.205-ca-jdk25.0.4.1-macosx_aarch64.tar.gz
Downloading <https://github.com/adoptium/temurin25-binaries/releases/download/jdk-25.0.5%2B8/OpenJDK25U-jdk_aarch64_mac_hotspot_25.0.5_8.tar.gz> to /Users/runner/work/kotlin-vipaccess/kotlin-vipaccess/.kotlin/shared-cache/download.cache/f8362503fc-OpenJDK25U-jdk_aarch64_mac_hotspot_25.0.5_8.tar.gz
Here you can see it download both zulu and temurin 25 JDK
j
Geez, that is very surprising. I'll have a look. Thanks for the report
thank you color 1
s
Also, the IDE shows the JDK is downloaded using the Foojay API, which I don’t think is correct anymore
🙏 1
j
I think I understand why you're getting both. The fact that the second JDK download happened to match your second vendor (
temurin
) in your config was a red herring. I'm betting you have some native platforms, and the Temurin 25 download is just the default JDK 25 used to run the native compiler. If you change your config, say to version 28 and distros
[zulu, corretto]
, your first download will be zulu 28, but the second will still be Temurin 25.
Improving the UX for this is a bit tricky. Let me explain. For the record, the runtime for the Kotlin/Native compiler is just that — a runtime. It has nothing to do with the actual compilation, it is not used for the Java standard library nor the JDK tools, it could very well just be a JRE, and it's an implementation detail. That's why I didn't make it follow the user's JDK configuration for the module. Whether you choose JDK 17 or 28 is irrelevant to the native compiler, so I find it better to reduce the unnecessary variability and force it to run with a fixed known JDK, which will be well tested in all our native-related tests. (That is different from KGP, which uses the user's JDK AFAIK).
Now, for that known JDK, I had chosen the default JDK because it increases the chances of choosing the same as the user's JDK, saving a download. Technically, the default JDK has no distro constraint, so it defaults to the entire list of vendors, in an order that starts with Temurin. However, the choice of JDK is made independently of the download cache or other config modules. So in your case it doesn't see that Zulu would also match, and sticks to its first choice: Temurin. The only thing that would actually make it pick another distro is if
JAVA_HOME
was set to some JDK 25. We could make this system smarter by actually looking at already downloaded JDKs outside of
JAVA_HOME
, maybe keeping some sort of registry, and make this affect the choice of JDK, but this would introduce non-determinism based on which provisioning runs first, so it's a trade-off on reproducibility. That would be a no-go: unlike
JAVA_HOME
, which is an input of the build, the variability here would be introduced based on races, which would break caching. We could instead look at the entire project configuration, and see if some module's JDK criteria is a subset of the default JDK criteria. That would be more deterministic, but still quite surprising to users (why does a change in one module affect a completely unrelated module?).
Another, probably better option IMO, is to abstract this away as part of the K/N toolchain provisioning, so it doesn't look confusing. We could even choose to use a JRE there. Eventually, we could use the native-imaged Kotlin compiler for this, and we won't even need a runtime at all.
👀 1