1

For example, if I'd like to add an extension on Inet4Address to be able to directly retrieve the underlying 32-bit address as an Int:

import jdk.internal.access.SharedSecrets

val Inet4Address.value
        get() = SharedSecrets.getJavaNetInetAddressAccess().addressValue(this)

IntelliJ IDEA does not show any errors, auto-complete works fine for it, etc.

However, when Gradle compileKotlin runs, I get these compilation errors:

Unresolved reference: access
Unresolved reference: SharedSecrets

This happens despite using a Java 11 toolchain spec in my build.gradle.kts:

java {
    toolchain {
        languageVersion.set(JavaLanguageVersion.of(11))
    }
}

How can I go about giving Kotlin access to the jdk.internal package with Gradle?

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
Jire
  • 9,680
  • 14
  • 52
  • 87
  • 2
    You basically need the `--add-exports` option for kotlinc, but I don't think that exists yet. – Sweeper Nov 06 '21 at 14:29
  • 2
    Note that `Inet4Address.hashCode()` returns the same value as `addressValue()` without accessing JDK internal APIs (and thus does not requires `--add-exports`). – apangin Nov 06 '21 at 17:07
  • 2
    Is this some special reflex some developers have? Seeing “internal” in the name of an API and responding with “must…use…this…API”? – Holger Nov 08 '21 at 09:02

0 Answers0