I investigated the possibility of moving Bootable ...
# kotlin-toolchain
r
I investigated the possibility of moving Bootable (github.com/rocketraman/bootable), a ~20-module JVM library plus examples, from Gradle to Kotlin Toolchain 0.13.0. Overall it went well, but I can’t migrate yet. Notes below in case they’re useful -- I did not look deeply into workarounds or solutions for the problems I ran into: What worked • The whole project builds with
kotlin build
, tests pass with kotlin test (TestBalloon + power-assert), and the examples start with
kotlin run
• Metro works as a third-party compilerPlugins entry • Our Gradle setup used custom source sets and hand-written POMs for optional DI integrations -- those became plain modules plus a small template, and the published POMs and Gradle module metadata came out right • Error messages are very good (e.g. “Maven Central requires artifact signatures”, pointing at both conflicting lines) What blocks me from migrating • Signing: it only works with an exported ASCII-armored key in
KOTLIN_TOOLCHAIN_SIGNING_KEY
. I sign with gpg-agent and the key lives on my YubiKey, so I’d need something like Gradle’s
useGpgCmd()
or support for an external signer Smaller things I hit • The javadoc jar is a placeholder; an easy way to ship Dokka output in it would be good. • Version:
settings.publishing.version
is a fixed string. Currently we get the release version from the vX.Y.Z git tag, so I’d need a CLI or env-var override, or some way to compute it • With
kotlin.version
pinned to 2.3.x, built-in powerAssert still adds kotlin-power-assert-runtime, which only exists for 2.4+, so dependency resolution fails • TestBalloon by default finds 0 tests because the toolchain passes class selectors to JUnit. Workaround: set `TESTBALLOON_INCLUDE_PATTERNS`: "*" via
settings.jvm.test.extraEnvironment
-- understood that TestBalloon does not officially support Toolchain yet, so the fact that it works at all is cool (and IDE support for TestBalloon tests with kotlin-toolchain is missing) • We still have to manually pick the Metro compiler artifact that matches the Kotlin version: 1.3.2 crashes on 2.4 with NoSuchMethodError, 1.4.5 works -- Gradle works the same way but ideally Toolchain would work better, and at least provide clearer error messages (maybe this is a Metro issue, not Toolchain) • If
mavenCentral
is enabled, signing is required even to publish to
mavenLocal
. There’s no per-run switch like Gradle’s
-PsigningRequired=false
•
kotlin publish <repo>
without -m fails when some modules (like non-published example modules) don’t declare that repo • Templates can’t override each other (a conflict is an error). Our Metro modules need languageVersion: 2.3 while everything else uses 2.1, so the override has to be repeated in each Metro module.yaml. Some way to layer templates would help. • A
file://
repository URL isn’t supported, which isn't normally an issue, but this ability can be useful for debugging • An unknown key in a template shows the right error, then an internal-error stack trace (propertyDeclaration is null)
🚀 1
🔥 2
👀 1
🙏 2
kodee loving 2
j
Thank you so much Raman! This kind of write-up is immensely useful to us 💜
amper intensifies 1
The javadoc jar is a placeholder; an easy way to ship Dokka output in it would be good
I initially planned integrating with Dokka for this, but the recent developments with Sonatype quotas for Maven Central made me think twice. In the long discussion with Brian Fox (from Sonatype) on this Slack (+ other internal ones), the idea surfaced that Dokka's content is not super suitable as a Javadoc JAR (at least not as HTML). The Dokka output would be repeated on all KMP target artifacts, which bloats the publication, and IDEs read the sources JAR instead when loading the KDocs anyway. For pure JVM libraries, it could make sense to use the Javadoc output of Dokka, though. We still have this ticket open for it (might need some updates): KTC-472 Support javadoc jar generation (for publication)
👍 2
> Version:
settings.publishing.version
is a fixed string. Currently we get the release version from the vX.Y.Z git tag, so I’d need a CLI or env-var override, or some way to compute it We have started a design to properly inject values into the build from outside (properties, env vars, stuff like that). This should eventually solve this problem. The issue to track this is the following: KTC-3854 Possibility to define different configs for different environments In the meantime, I agree it's a bit inconvenient. What we do ourselves in our own CI is we change the YAML from the CI job before publication 😅
👍 1
👀 1
With
kotlin.version
pinned to 2.3.x, built-in powerAssert still adds kotlin-power-assert-runtime, which only exists for 2.4+, so dependency resolution fails
Oh thank you! For some reason I missed this. I created this issue for tracking: KTC-6057 Implicit kotlin-power-assert-runtime fails DR with Kotlin < 2.4
👍 1
> TestBalloon by default finds 0 tests because the toolchain passes class selectors to JUnit. Workaround: set `TESTBALLOON_INCLUDE_PATTERNS`: "*" via
settings.jvm.test.extraEnvironment
-- understood that TestBalloon does not officially support Toolchain yet, so the fact that it works at all is cool (and IDE support for TestBalloon tests with kotlin-toolchain is missing) @Oliver.O is actually pretty involved in making things work with Kotlin Toolchain. The test selector issue is a known problem that we'll eventually need to address somehow on the Kotlin Toolchain side. It's not 100% clear how we'll support arbitrary JUnit engines via our test filters, but we'll need to think about it. Some suggestions by Oliver here: youtrack.jetbrains.com/issue/KTC-4080/Simplify-test-filtering-options#focus=Comments-27-13637610…
👍 1
We still have to manually pick the Metro compiler artifact that matches the Kotlin version: 1.3.2 crashes on 2.4 with NoSuchMethodError, 1.4.5 works -- Gradle works the same way but ideally Toolchain would work better, and at least provide clearer error messages (maybe this is a Metro issue, not Toolchain)
I think @Youssef is working on something that will make it easier for compiler plugin authors to support multiple Kotlin versions. Hopefully this will eventually get better. I don't think there is a lot we can do on the Kotlin Toolchain side for now, apart maybe from providing a way to reference the Kotlin version from inside the compiler plugin coordinates (so that compiler plugin authors can publish versions like
1.2.3-kotlin-2.4.21
(a bit like KSP used to do). But again, if there is a better long-term solution, maybe this is not needed.
👍 1
> If
mavenCentral
is enabled, signing is required even to publish to
mavenLocal
. There’s no per-run switch like Gradle’s
-PsigningRequired=false
> Thanks! I think this was broken when implementing publication for KMP libraries. We moved the sigining code to some common place that is now also used to publish to maven local, and thus missing signatures now also fail there. Now tracked there: KTC-6058
kotlin publish mavenLocal
fails on missing signature when signing is enabled
👀 1
kotlin publish <repo>
without -m fails when some modules (like non-published example modules) don’t declare that repo
Thank you! That's definitely on me: KTC-6059
kotlin publish
without
-m
incorrectly requires in non-published modules
👀 1
> Templates can’t override each other (a conflict is an error). Our Metro modules need languageVersion: 2.3 while everything else uses 2.1, so the override has to be repeated in each Metro module.yaml. Some way to layer templates would help. Have you tried nested templates (templates using
apply
)? This is one of their uses. Please check the very last part of this documentation page: kotlin-toolchain.org/latest/user-guide/templates#…
👀 1
A
file://
repository URL isn’t supported, which isn't normally an issue, but this ability can be useful for debugging
That would be KTC-5759 Allow publishing to a custom local directory
👀 1
> An unknown key in a template shows the right error, then an internal-error stack trace (propertyDeclaration is null) Could you please share a reproducer? I can't seem to reproduce. I get the clean error, and no internal stack:
👀 1
r
Have you tried nested templates (templates using apply)? This is one of their uses. Please check the very last part of this documentation page:
Confirmed, that works, thank you.
Could you please share a reproducer? I can't seem to reproduce. I get the clean error, and no internal stack: (edited)
Reproducer: it seems specific to
description
, which is valid in
module.yaml
but not in a template. Unknown keys like
foo: bar
give the clean error. On 0.13.0:
Copy code
project.yaml                  modules:
                                - lib
common.module-template.yaml   description: Some description
lib/module.yaml               product: jvm/lib
                              apply:
                                - //common.module-template.yaml
lib/src/Hello.kt              fun hello() = "hi"
kodee loving 1
🙏 1
Any workarounds for signing from yubikey? I haven't looked into it deeply but is there a possibility of replacing the signing command with a plugin?
o
Regarding Metro, I'd suggest to raise the versioning issue with that project. Metro has been the trailblazer in multi-version compiler compatibility, and knows how to obtain the Kotlin compiler version used: github.com/ZacSweers/metro/blob/…/CompatContext.kt#… Maybe this can be improved on their side.
👍 1
r
One other thing... a warm clean build plus tests took 11.4 s with the Kotlin Toolchain against 7 s for ./gradlew build with a warm daemon. This is a rough single sample, not a benchmark, and this is a small project so it probably pays more of the fixed startup build costs as a proportion of the total time. But thought I'd throw it out there in case there are simple ways to improve this gap. Please do not introduce anything like the gradle daemon 🙂
Created this Metro issue regarding the version check: https://github.com/ZacSweers/metro/issues/2984
j
> Any workarounds for signing from yubikey? I haven't looked into it deeply but is there a possibility of replacing the signing command with a plugin? Ah I forgot to address that one. So at the moment I don't see any way to work around this, unfortunately. The rationale that led me to forego the support of signing via a gpg binary is that most publications are done from safe/isolated/reproducible machines - so from some CI workflow. Publishing from local machines is usually not recommended because it exposes the publication to potential pollution with local changes or environment configs, and random variability. So I wonder why you need support for this. Do you publish from your local machine? Don't you find this a bit risky?
@rocketraman regarding the slow build, I would be really really interested in the telemetry for this. Could you please share the logs directory of that build with the Kotlin Toolchain? (Or just the open telemetry traces of you prefer). I'd like to see why it's slow.
r
> So I wonder why you need support for this. Do you sign from your local machine? Don't you find this a bit risky? Yeah I do for now. I have preferred signing from my hardware key. But yes, I see the advantages of doing it from CI. Let me look into creating a signing subkey or something. > @rocketraman regarding the slow build, I would be really really interested in the telemetry for this. Could you please share the logs directory of that build with the Kotlin Toolchain? (Or just the open telemetry traces of you prefer). I'd like to see why it's slow. (edited) Attached. From a clean kotlin build (11.8 s) followed by kotlin test (2.1 s) on 0.13.0. Claude rendered this timeline. With
JAVA_HOME
unset, “Get provisioned JDK” takes up to 1.3 s per task even with the JDK already cached; with
JAVA_HOME
set it drops to 0.06 s and the build goes from 11.8 s to 10.2 s. I'm not sure why the first 3 small modules take 1.5s to compile. di-bench appears to take a long time to compile (long enough that it is critical path) takes ~6.4 s in the compiler alone: ~2 s each for the Kodein and Metro code and ~2.3 s even with both removed. Gradle seems faster on this module for some reason. If I can dig into anything here, let me know.
@joffrey Looking more into the subkey option... With an
[SC]
primary on a smartcard,
KOTLIN_TOOLCHAIN_SIGNING_KEY
set to
gpg --export-secret-subkeys '<subkey>!'
(stub primary plus one signing subkey) fails with
PGP signing failed … NullPointerException: … OpenPGPSecretKey.unlock(char[]) is null”
BouncyCastle’s
addSigningKey
also selects the stub primary. gpg signs fine with the same export. Could the toolchain skip keys without secret material, or let us pick the signing subkey (like Gradle’s
signing.keyId
)?
🙏 1
o
Regarding a better test selection (filtering) for the Kotlin Toolchain / TestBalloon combination, I have some concrete ideas: We could add another pair of options to Kotlin Toolchain (like
--include-pattern
,
--exclude-pattern
) and another
TestFilter
subclass, which basically holds the corresponding attributes (list of strings). These would be passed to the respective test framework unchanged (without parsing or interpretation), except for an element delimiter (e.g. picking one that's really unlikely to be part of a test name, like TestBalloon's ⬥). Environment variables could serve as a single mechanism to make these pattern lists available on all platforms except browsers (like
KOTLIN_TEST_INCLUDE
,
KOTLIN_TEST_EXCLUDE
). For browsers, we could use URL parameters of the same name. For the Kotlin Toolchain IDE plugin, we'd need an integration point for a test framework's IDE plugin. We'd need just two functions with the following capabilities: • Take a
PsiElement
, and provide its test element characteristics like
type
(test or suite),
includePattern
,
displayName
. The Toolchain plugin could then display a run gutter icon and supply the run configuration's
--include-pattern
argument. • Take the framework-specific test element's
pathId
from a test event reported during execution, and provide its
PsiElement
. The Toolchain plugin could then support "jump to source" from test results and display run gutter icon's test result status (success, failure, ...). If there is interest and it would not collide with current priorities in the Toolchain roadmap: I could try to come up with a PR for Kotlin Toolchain. And for IDE plugin integration, I could try to create a more elaborate spec.
j
Attached. From a clean kotlin build (11.8 s) followed by kotlin test (2.1 s) on 0.13.0. Claude rendered this timeline
Sorry I was asking for the actual telemetry traces from the logs folder (
build/logs/amper_<datetime>_<command>/telemetry/kotlin_cli_traces.json
), or the whole
build/logs/amper_<datetime>_<command>
folder if you're ok with that. That would be way more helpful. This rendered view doesn't say much
With an
[SC]
primary on a smartcard,
KOTLIN_TOOLCHAIN_SIGNING_KEY
set to
gpg --export-secret-subkeys '<subkey>!'
(stub primary plus one signing subkey) fails with
PGP signing failed … NullPointerException: … OpenPGPSecretKey.unlock(char[]) is null"
BouncyCastle’s
addSigningKey
also selects the stub primary. gpg signs fine with the same export. Could the toolchain skip keys without secret material, or let us pick the signing subkey (like Gradle’s
signing.keyId
)?
Thanks for exploring this option! I think we need to support subkeys, that would be more correct. Let me open an issue for this: KTC-6065 Allow configuring a signing subkey
r
@joffrey the traces are also above
🤔 1
dm 1
j
Strange, I don't see the traces anywhere in the thread, I only see the image 🤔 Maybe you could try by DM? 🙏🏼 EDIT: received in DM ✅
I also opened that one for the
description
in templates, thanks for the reproducer! KTC-6066 Internal error when using a module-only property in a template
I also opened this to track demand for GPG signing with a local
gpg
binary: KTC-6067 Allow signing with a local GPG binary/agent
> Attached. From a clean kotlin build (11.8 s) followed by kotlin test (2.1 s) on 0.13.0. Claude rendered this timeline. > With
JAVA_HOME
unset, “Get provisioned JDK” takes up to 1.3 s per task even with the JDK already cached; with
JAVA_HOME
set it drops to 0.06 s and the build goes from 11.8 s to 10.2 s. About the JDK stuff, this is because on clean builds we re-check the list of JDKs. It's technically in a shared cache, but the information that tracks whether it's up to date is still stored per project. So if you clean your
build
directory, the Kotlin Toolchain will re-download and decompress the JDK list just to be sure. This is what takes 1.3s. It is actually not really per-task. In the traces, only one of these spans actually does the download/decompression. The others are just waiting on it (because they are synchronized). You can see they have
from-memory-cache=true
and no nested spans. This shouldn't affect hot builds or tests, though. You can see the traces for the
test
run on hot caches does the JDK check in ~20ms for the first module(s) and then sub-millisecond (<150μs) for anything that needs it later.
👍 1
> I'm not sure why the first 3 small modules take 1.5s to compile. > di-bench appears to take a long time to compile (long enough that it is critical path) takes ~6.4 s in the compiler alone: ~2 s each for the Kodein and Metro code and ~2.3 s even with both removed. Gradle seems faster on this module for some reason. If I can dig into anything here, let me know. Regarding compilation, one possible cause for the difference with Gradle is that we're not using (yet?) the Kotlin compiler daemon in the Kotlin Toolchain, so the compilation happens in-process. The first compilation in any
build
call that is not fully cached therefore need to load the compiler's classes, which is quite significant. One thing you could check is whether you have any Gradle or Kotlin daemon running before doing the clean build. That would skew the results of the Gradle side for the comparison. I'm exploring some options with AOT caching to speed the startup of our CLI, and it can give more than 1.3x speedups in some cases on clean builds, and 2.5x on builds with a hot cache. If you have a small-ish project, compilation startup might matter.
👍 1
r
My summary writeup on this is here: https://github.com/rocketraman/bootable/blob/master/docs/kotlin-toolchain-evaluation.adoc -- I'll probably hold off on the migration for a bit until some of the identified issues get resolved, but looking forward to the day.
🔥 3
🙏 1