linkJvm

fun NativeBinary.linkJvm()

Adds the JVM runtime library (libjvm) to the native linker options.

The JDK is taken from the Gradle Java toolchain matching JniLibProducerExtension.expectedJdkVersion, which is the right choice as long as the target architecture matches the host one. For cross-compilation point linkJvm at a JDK built for the target instead, which downloadCompatibleJdk provides:

linkJvm()                                                               // toolchain of the host
linkJvm(downloadCompatibleJdk("17.0.13.11.1")) // JDK of the target
linkJvm(javaHome = file("/opt/jdk-17-linux-x64")) // File
linkJvm(javaHome = providers.gradleProperty("jni.jdk.x64").map(::file)) // or a Provider
linkJvm(languageVersion = 17) // toolchain by version
linkJvm(toolchainSpec = {
languageVersion = JavaLanguageVersion.of(17)
})

A call for a binary replaces the JDK selected by a previous call for the same binary, and the selected JDK is reused by linkJAwt. The selected JDK is validated against the target architecture when the linker options are read.

This function adds only libjvm. Call linkJAwt when the native library also uses JAWT, and linkX11IfLinux on Linux when the AWT runtime needs X11.


fun NativeBinary.linkJvm(languageVersion: Int)

Adds the JVM runtime library (libjvm) linked against the Gradle Java toolchain of the given languageVersion.

See the parameterless linkJvm for details.


fun NativeBinary.linkJvm(javaHome: Provider<Directory>)

Adds the JVM runtime library (libjvm) linked against the JDK in javaHome.

This is the overload for a home directory a build works out itself.

See the parameterless linkJvm for details.


fun NativeBinary.linkJvm(javaHome: Path)

Adds the JVM runtime library (libjvm) linked against the JDK at javaHome.

This is the overload to use for a target that is not the host, where no toolchain can help because Gradle only serves JDKs for the host: downloadCompatibleJdk fetches one built for the target, and its result is what this takes.

See the parameterless linkJvm for details.


fun NativeBinary.linkJvm(javaHome: File)
@JvmName(name = "linkJvmFileProvider")
fun NativeBinary.linkJvm(javaHome: Provider<File>)

Adds the JVM runtime library (libjvm) linked against the JDK at javaHome.

The path is accepted as a File or as a path relative to the project directory. See the parameterless linkJvm for details.


fun NativeBinary.linkJvm(toolchainSpec: Action<JavaToolchainSpec>)

Adds the JVM runtime library (libjvm) linked against the JDK resolved from toolchainSpec.

Unlike an explicit javaHome, the JDK is provisioned by Gradle. Gradle only serves JDKs for the host architecture, so this overload selects the version, vendor and implementation of the JDK rather than its architecture. See the parameterless linkJvm for details.