Skip to content

Fix GraalVM native build error caused by stale substitution target in v8.x - #601

Merged
oshai merged 4 commits into
masterfrom
copilot/fix-native-build-error
May 3, 2026
Merged

oshai merged 4 commits into
masterfrom
copilot/fix-native-build-error

Conversation

Copilot AI commented May 3, 2026 •

Copy link
Copy Markdown
Contributor

In v8.x, io.github.oshai.kotlinlogging.internal.KLoggerFactory was moved to io.github.oshai.kotlinlogging.KotlinLoggingConfiguration, but the GraalVM @TargetClass substitution still referenced the old internal class. When Logback is absent from the native image classpath, the onlyWith condition activates the substitution — which then fails because the target class no longer exists at that location.

Changes

  • Renamed Target_io_github_oshai_kotlinlogging_internal_KLoggerFactory.kt → Target_io_github_oshai_kotlinlogging_KotlinLoggingConfiguration.kt (following the Target_ naming convention)
  • Updated @TargetClass to target "io.github.oshai.kotlinlogging.KotlinLoggingConfiguration" (the v8.x home of the logger factory detection logic)
  • Updated the substituted method from logger$kotlin_logging(name: String): KLogger to detectLogger(): KLoggerFactory — the method in KotlinLoggingConfiguration that references LogbackLoggerFactory and needs to be bypassed when Logback is not on the classpath
  • Restored the original LogbackNotOnClasspath condition — since the target class now correctly exists in v8.x, no extra class-existence check is needed

This ensures GraalVM substitutes the correct method in the correct class, preventing native image build failures when Logback is absent from the classpath.

Copilot AI linked an issue May 3, 2026 that may be closed by this pull request
@github-actions

github-actions Bot commented May 3, 2026

Copy link
Copy Markdown

Thanks for the contribution! If you haven't done so it is usually better to discuss your intentions either by opening a new issue or in our slack channel.

…n to check if target class exists

Agent-Logs-Url: https://github.com/oshai/kotlin-logging/sessions/728f006b-d368-4f73-92f3-ca9855e1798f

Co-authored-by: oshai <2683969+oshai@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix native build error after upgrading to v8.x Fix GraalVM native build error caused by stale substitution target in v8.x May 3, 2026
Copilot AI requested a review from oshai May 3, 2026 11:58
Copilot finished work on behalf of oshai May 3, 2026 11:58

@oshai oshai left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LoggerFactory moved not deleted

Copilot AI commented May 3, 2026

Copy link
Copy Markdown
Contributor Author

LoggerFactory moved not deleted

Fixed in 5b822c2 — the substitution now correctly targets KotlinLoggingConfiguration in io.github.oshai.kotlinlogging (substituting detectLogger()) instead of the deleted internal class.

Copilot finished work on behalf of oshai May 3, 2026 12:12
Copilot AI requested a review from oshai May 3, 2026 12:12
@oshai
oshai marked this pull request as ready for review May 3, 2026 12:29
@oshai
oshai requested a review from Copilot May 3, 2026 12:30

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the JVM-side GraalVM substitution used by kotlin-logging’s native-image support so it targets the v8.x logger-detection implementation in KotlinLoggingConfiguration instead of the removed internal KLoggerFactory target.

Changes:

  • Renames the Graal substitution class/file to match the new v8.x target naming.
  • Retargets @TargetClass from the removed internal factory to io.github.oshai.kotlinlogging.KotlinLoggingConfiguration.
  • Replaces the old substituted logger-construction method with a substitution for detectLogger() that avoids the Logback path when Logback is absent.
Comments suppressed due to low confidence (1)

src/jvmMain/kotlin/io/github/oshai/kotlinlogging/internal/Target_io_github_oshai_kotlinlogging_KotlinLoggingConfiguration.kt:33

  • This substitution no longer preserves the JVM detectLogger() behavior for the kotlin-logging-to-direct=true override. In native images built without Logback, that property will now be ignored and loggerFactory will fall back to SLF4J, which breaks the documented way to opt into DirectLoggerFactory on JVM.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@oshai
oshai merged commit 8ab1a8a into master May 3, 2026
9 checks passed
@oshai
oshai deleted the copilot/fix-native-build-error branch May 3, 2026 13:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Upgrade to v8.x causes native build error

3 participants